From a7595347f3fda9a348172a617f3eeed605417a75 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 29 Apr 2017 10:41:56 +0200 Subject: [PATCH] Make the UpdatesThread a daemon (closes #60) --- telethon/network/mtproto_sender.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/telethon/network/mtproto_sender.py b/telethon/network/mtproto_sender.py index 498bc8fb..2a38fd65 100755 --- a/telethon/network/mtproto_sender.py +++ b/telethon/network/mtproto_sender.py @@ -46,7 +46,8 @@ class MtProtoSender: self.updates_thread_sleep = None self.updates_thread = Thread( - target=self.updates_thread_method, name='UpdatesThread') + name='UpdatesThread', daemon=True, + target=self.updates_thread_method) # The "updates" thread must also be running to make periodic ping requests. self.set_updates_thread(running=True) @@ -399,13 +400,12 @@ class MtProtoSender: # Always sleep a bit before each iteration to relax the CPU, # since it's possible to early 'continue' the loop to reach # the next iteration, but we still should to sleep. - if self.updates_thread_running: - if self.updates_thread_sleep: - sleep(self.updates_thread_sleep) - self.updates_thread_sleep = None - else: - # Longer sleep if we're not expecting updates (only pings) - sleep(0.1 if self.on_update_handlers else 1) + if self.updates_thread_sleep: + sleep(self.updates_thread_sleep) + self.updates_thread_sleep = None + else: + # Longer sleep if we're not expecting updates (only pings) + sleep(0.1 if self.on_update_handlers else 1) # Only try to receive updates if we're not waiting to receive a request if not self.waiting_receive: