From f1bca0fd06caa38dc7bed5d50ed138c5f26bd29c Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 30 Sep 2017 18:44:37 +0200 Subject: [PATCH] Fix setting None update workers not causing all threads to stop --- telethon/update_state.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/telethon/update_state.py b/telethon/update_state.py index 7e25549f..fa1963a3 100644 --- a/telethon/update_state.py +++ b/telethon/update_state.py @@ -79,11 +79,14 @@ class UpdateState: """Raises "StopIterationException" on the worker threads to stop them, and also clears all of them off the list """ - with self._updates_lock: - # Insert at the beginning so the very next poll causes an error - # TODO Should this reset the pts and such? - self._updates.appendleft(StopIteration()) - self._updates_available.set() + 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? + for _ in range(self._workers): + self._updates.appendleft(StopIteration()) + self._updates_available.set() for t in self._worker_threads: t.join()