From 5a7a62c3d860242c43794868325db53efc43c2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Sun, 24 Apr 2016 13:43:42 +0200 Subject: [PATCH] release semaphore on exceptions --- telegram/ext/dispatcher.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/telegram/ext/dispatcher.py b/telegram/ext/dispatcher.py index a55b8f04d..86dd2152d 100644 --- a/telegram/ext/dispatcher.py +++ b/telegram/ext/dispatcher.py @@ -61,10 +61,13 @@ def run_async(func): """ A wrapper to run a thread in a thread pool """ - result = func(*pargs, **kwargs) - semaphore.release() - with async_lock: - async_threads.remove(current_thread()) + try: + result = func(*pargs, **kwargs) + finally: + semaphore.release() + + with async_lock: + async_threads.remove(current_thread()) return result @wraps(func)