Convert daemon threads back into normal threads.

This may need to be reverted if CTRL-C handling breaks, but everything
works fine so far in testing.

Resolves issue #95.
This commit is contained in:
Lance Stout 2011-11-20 12:15:39 -08:00
parent d1a945a305
commit fba60ffff1
3 changed files with 15 additions and 10 deletions

View file

@ -87,11 +87,16 @@ class Waiter(BaseHandler):
if timeout is None: if timeout is None:
timeout = self.stream().response_timeout timeout = self.stream().response_timeout
try: elapsed_time = 0
stanza = self._payload.get(True, timeout) stanza = False
except queue.Empty: while elapsed_time < timeout and not self.stream().stop.is_set():
stanza = False try:
log.warning("Timed out waiting for %s", self.name) stanza = self._payload.get(True, 1)
break
except queue.Empty:
elapsed_time += 1
if elapsed_time >= timeout:
log.warning("Timed out waiting for %s", self.name)
self.stream().remove_handler(self.name) self.stream().remove_handler(self.name)
return stanza return stanza

View file

@ -134,7 +134,6 @@ class Scheduler(object):
if threaded: if threaded:
self.thread = threading.Thread(name='sheduler_process', self.thread = threading.Thread(name='sheduler_process',
target=self._process) target=self._process)
self.thread.daemon = True
self.thread.start() self.thread.start()
else: else:
self._process() self._process()

View file

@ -466,7 +466,7 @@ class XMLStream(object):
""" """
def _handle_session_timeout(): def _handle_session_timeout():
if not self.session_started_event.isSet(): if not self.session_started_event.is_set():
log.debug("Session start has taken more " + \ log.debug("Session start has taken more " + \
"than %d seconds", self.session_timeout) "than %d seconds", self.session_timeout)
self.disconnect(reconnect=self.auto_reconnect) self.disconnect(reconnect=self.auto_reconnect)
@ -1055,7 +1055,6 @@ class XMLStream(object):
def start_thread(name, target): def start_thread(name, target):
self.__thread[name] = threading.Thread(name=name, target=target) self.__thread[name] = threading.Thread(name=name, target=target)
self.__thread[name].daemon = True
self.__thread[name].start() self.__thread[name].start()
for t in range(0, HANDLER_THREADS): for t in range(0, HANDLER_THREADS):
@ -1255,7 +1254,7 @@ class XMLStream(object):
""" """
log.debug("Loading event runner") log.debug("Loading event runner")
try: try:
while not self.stop.isSet(): while not self.stop.is_set():
try: try:
wait = self.wait_timeout wait = self.wait_timeout
event = self.event_queue.get(True, timeout=wait) event = self.event_queue.get(True, timeout=wait)
@ -1320,7 +1319,9 @@ class XMLStream(object):
""" """
try: try:
while not self.stop.is_set(): while not self.stop.is_set():
self.session_started_event.wait() while not self.stop.is_set and \
not self.session_started_event.is_set():
self.session_started_event.wait(timeout=1)
if self.__failed_send_stanza is not None: if self.__failed_send_stanza is not None:
data = self.__failed_send_stanza data = self.__failed_send_stanza
self.__failed_send_stanza = None self.__failed_send_stanza = None