From b78ceeed10bcd34fbd6d8a8b6a19f356475badf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Wed, 6 Jan 2016 15:35:55 +0100 Subject: [PATCH] fix race condition in dispatcher --- telegram/dispatcher.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/telegram/dispatcher.py b/telegram/dispatcher.py index 1fe997299..07ea8ecbc 100644 --- a/telegram/dispatcher.py +++ b/telegram/dispatcher.py @@ -26,6 +26,7 @@ from functools import wraps from inspect import getargspec from threading import Thread, BoundedSemaphore, Lock from re import match +from time import sleep from telegram import (TelegramError, Update, NullHandler) @@ -175,6 +176,7 @@ class Dispatcher: update = self.update_queue.get() if type(update) is self._Stop: + self.running = False break self.processUpdate(update) @@ -200,8 +202,9 @@ class Dispatcher: """ with self.__lock: if self.running: - self.running = False self.update_queue.put(self._Stop()) + while self.running: + sleep(0.1) def processUpdate(self, update): """