From de332471df436eb4d4b45c6614528de709b6095f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 29 Apr 2018 20:30:32 +0200 Subject: [PATCH] Join net worker threads before stopping. Fixes #62 --- pyrogram/session/session.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 0013ef68..37a42ec6 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -120,6 +120,8 @@ class Session: self.next_salt_thread = None self.next_salt_thread_event = Event() + self.net_worker_list = [] + self.is_connected = Event() def start(self): @@ -128,7 +130,14 @@ class Session: self.connection.connect() for i in range(self.NET_WORKERS): - Thread(target=self.net_worker, name="NetWorker#{}".format(i + 1)).start() + self.net_worker_list.append( + Thread( + target=self.net_worker, + name="NetWorker#{}".format(i + 1) + ) + ) + + self.net_worker_list[-1].start() Thread(target=self.recv, name="RecvThread").start() @@ -190,6 +199,11 @@ class Session: for i in range(self.NET_WORKERS): self.recv_queue.put(None) + for i in self.net_worker_list: + i.join() + + self.net_worker_list.clear() + for i in self.results.values(): i.event.set()