mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-23 06:50:29 +01:00
commit
f8b13440c1
3 changed files with 18 additions and 10 deletions
|
@ -128,10 +128,16 @@ class ConversationHandler(Handler):
|
|||
self.logger.debug('waiting for promise...')
|
||||
|
||||
old_state, new_state = state
|
||||
new_state.result(timeout=self.run_async_timeout)
|
||||
error = False
|
||||
try:
|
||||
res = new_state.result(timeout=self.run_async_timeout)
|
||||
except Exception as exc:
|
||||
self.logger.exception("promise function raised exception: %s" %
|
||||
exc)
|
||||
error = True
|
||||
|
||||
if new_state.done.is_set():
|
||||
self.update_state(new_state.result(), key)
|
||||
if not error and new_state.done.is_set():
|
||||
self.update_state(res, key)
|
||||
state = self.conversations.get(key)
|
||||
|
||||
else:
|
||||
|
|
|
@ -159,12 +159,8 @@ class Dispatcher(object):
|
|||
len(self.__async_threads))
|
||||
break
|
||||
|
||||
try:
|
||||
promise.run()
|
||||
|
||||
except:
|
||||
self.logger.exception("run_async function raised exception")
|
||||
|
||||
def run_async(self, func, *args, **kwargs):
|
||||
"""Queue a function (with given args/kwargs) to be run asynchronously.
|
||||
|
||||
|
|
|
@ -30,17 +30,23 @@ class Promise(object):
|
|||
self.kwargs = kwargs
|
||||
self.done = Event()
|
||||
self._result = None
|
||||
self._exception = None
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
self._result = self.pooled_function(*self.args, **self.kwargs)
|
||||
|
||||
except:
|
||||
raise
|
||||
except Exception as exc:
|
||||
self._exception = exc
|
||||
|
||||
finally:
|
||||
self.done.set()
|
||||
|
||||
def __call__(self):
|
||||
self.run()
|
||||
|
||||
def result(self, timeout=None):
|
||||
self.done.wait(timeout=timeout)
|
||||
if self._exception is not None:
|
||||
raise self._exception
|
||||
return self._result
|
||||
|
|
Loading…
Reference in a new issue