mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-04-25 11:23:42 +03:00
Better attempt at joining update worker threads
This commit is contained in:
parent
3d68c879dd
commit
771c573db1
|
@ -62,23 +62,23 @@ class UpdateState:
|
||||||
"""
|
"""
|
||||||
self.stop_workers()
|
self.stop_workers()
|
||||||
self._workers = n
|
self._workers = n
|
||||||
if n is None:
|
if n is not None:
|
||||||
while self._updates:
|
|
||||||
self._updates.get()
|
|
||||||
else:
|
|
||||||
self.setup_workers()
|
self.setup_workers()
|
||||||
|
|
||||||
workers = property(fget=get_workers, fset=set_workers)
|
workers = property(fget=get_workers, fset=set_workers)
|
||||||
|
|
||||||
def stop_workers(self):
|
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:
|
if self._workers:
|
||||||
with self._updates_lock:
|
with self._updates_lock:
|
||||||
# Insert at the beginning so the very next poll causes an error
|
# Insert at the beginning so the very next poll causes an error
|
||||||
# on all the worker threads
|
# on all the worker threads
|
||||||
# TODO Should this reset the pts and such?
|
# TODO Should this reset the pts and such?
|
||||||
|
while self._updates:
|
||||||
|
self._updates.get()
|
||||||
for _ in range(self._workers):
|
for _ in range(self._workers):
|
||||||
self._updates.put(StopIteration())
|
self._updates.put(StopIteration())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user