Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion telegram/ext/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,20 @@ def run_async(self, func, *args, **kwargs):
self.__async_queue.put(promise)
return promise

def start(self):
def start(self, ready=None):
"""Thread target of thread 'dispatcher'.

Runs in background and processes the update queue.

Args:
ready (:obj:`threading.Event`, optional): If specified, the event will be set once the
dispatcher is ready.

"""
if self.running:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we do ready.set() here as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense. i'll fix.

self.logger.warning('already running')
if ready is not None:
ready.set()
return

if self.__exception_event.is_set():
Expand All @@ -202,6 +208,9 @@ def start(self):
self.running = True
self.logger.debug('Dispatcher started')

if ready is not None:
ready.set()

while 1:
try:
# Pop update from update queue.
Expand Down
5 changes: 4 additions & 1 deletion telegram/ext/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ def start_polling(self,

# Create & start threads
self.job_queue.start()
self._init_thread(self.dispatcher.start, "dispatcher")
dispatcher_ready = Event()
self._init_thread(self.dispatcher.start, "dispatcher", ready=dispatcher_ready)
self._init_thread(self._start_polling, "updater", poll_interval, timeout,
read_latency, bootstrap_retries, clean, allowed_updates)

dispatcher_ready.wait()

# Return the update queue so the main thread can insert updates
return self.update_queue

Expand Down