diff options
author | Lance Stout <lancestout@gmail.com> | 2011-11-20 12:15:39 -0800 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2011-11-20 12:17:35 -0800 |
commit | fba60ffff11d42f2e6edecdfcb4200a50a844bed (patch) | |
tree | e3cdc144feaa170323914d8087a850693f02a1b1 /sleekxmpp/xmlstream | |
parent | d1a945a3053b82d2553a48f2d2c5c69664e6fde4 (diff) | |
download | slixmpp-fba60ffff11d42f2e6edecdfcb4200a50a844bed.tar.gz slixmpp-fba60ffff11d42f2e6edecdfcb4200a50a844bed.tar.bz2 slixmpp-fba60ffff11d42f2e6edecdfcb4200a50a844bed.tar.xz slixmpp-fba60ffff11d42f2e6edecdfcb4200a50a844bed.zip |
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.
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r-- | sleekxmpp/xmlstream/handler/waiter.py | 15 | ||||
-rw-r--r-- | sleekxmpp/xmlstream/scheduler.py | 1 | ||||
-rw-r--r-- | sleekxmpp/xmlstream/xmlstream.py | 9 |
3 files changed, 15 insertions, 10 deletions
diff --git a/sleekxmpp/xmlstream/handler/waiter.py b/sleekxmpp/xmlstream/handler/waiter.py index 21fc347c..a64b6a9b 100644 --- a/sleekxmpp/xmlstream/handler/waiter.py +++ b/sleekxmpp/xmlstream/handler/waiter.py @@ -87,11 +87,16 @@ class Waiter(BaseHandler): if timeout is None: timeout = self.stream().response_timeout - try: - stanza = self._payload.get(True, timeout) - except queue.Empty: - stanza = False - log.warning("Timed out waiting for %s", self.name) + elapsed_time = 0 + stanza = False + while elapsed_time < timeout and not self.stream().stop.is_set(): + try: + 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) return stanza diff --git a/sleekxmpp/xmlstream/scheduler.py b/sleekxmpp/xmlstream/scheduler.py index 58219257..45d24272 100644 --- a/sleekxmpp/xmlstream/scheduler.py +++ b/sleekxmpp/xmlstream/scheduler.py @@ -134,7 +134,6 @@ class Scheduler(object): if threaded: self.thread = threading.Thread(name='sheduler_process', target=self._process) - self.thread.daemon = True self.thread.start() else: self._process() diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index 6d53022c..8d1c7e36 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -466,7 +466,7 @@ class XMLStream(object): """ 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 " + \ "than %d seconds", self.session_timeout) self.disconnect(reconnect=self.auto_reconnect) @@ -1055,7 +1055,6 @@ class XMLStream(object): def start_thread(name, target): self.__thread[name] = threading.Thread(name=name, target=target) - self.__thread[name].daemon = True self.__thread[name].start() for t in range(0, HANDLER_THREADS): @@ -1255,7 +1254,7 @@ class XMLStream(object): """ log.debug("Loading event runner") try: - while not self.stop.isSet(): + while not self.stop.is_set(): try: wait = self.wait_timeout event = self.event_queue.get(True, timeout=wait) @@ -1320,7 +1319,9 @@ class XMLStream(object): """ try: 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: data = self.__failed_send_stanza self.__failed_send_stanza = None |