From 771c573db1304292492e9a65288cd4802ace40dc Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 1 Mar 2018 13:31:39 +0100 Subject: [PATCH] Better attempt at joining update worker threads --- telethon/update_state.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/telethon/update_state.py b/telethon/update_state.py index 6fa0b12a..1ac2e00d 100644 --- a/telethon/update_state.py +++ b/telethon/update_state.py @@ -62,23 +62,23 @@ class UpdateState: """ self.stop_workers() self._workers = n - if n is None: - while self._updates: - self._updates.get() - else: + if n is not None: self.setup_workers() workers = property(fget=get_workers, fset=set_workers) def stop_workers(self): - """Raises "StopIterationException" on the worker threads to stop them, - and also clears all of them off the list + """ + Raises "StopIterationException" on the worker threads to stop + them, and also clears all the workers/updates from the lists. """ if self._workers: with self._updates_lock: # Insert at the beginning so the very next poll causes an error # on all the worker threads # TODO Should this reset the pts and such? + while self._updates: + self._updates.get() for _ in range(self._workers): self._updates.put(StopIteration())