Set a timeout when waiting for threads.

If calling disconnect() from a non-threaded event handler, deadlock can
happen as disconnect() is waiting for threads to close, but the event
runner is blocked by a handler waiting for disconnect() to return.

It is best to specify threaded=True for event handlers which may call
disconnect().
This commit is contained in:
Lance Stout 2012-04-29 14:45:00 -07:00
parent fd81bab906
commit 08716c35fd

View file

@ -1202,7 +1202,7 @@ class XMLStream(object):
if self.__thread_count != 0: if self.__thread_count != 0:
log.debug("Waiting for %s threads to exit." % log.debug("Waiting for %s threads to exit." %
self.__thread_count) self.__thread_count)
self.__thread_cond.wait() self.__thread_cond.wait(4)
if self.__thread_count != 0: if self.__thread_count != 0:
raise Exception("Hanged threads: %s" % threading.enumerate()) raise Exception("Hanged threads: %s" % threading.enumerate())