mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-07 02:59:57 +01:00
add run_async decorator
This commit is contained in:
parent
d363185031
commit
63a8700258
1 changed files with 14 additions and 1 deletions
|
@ -15,6 +15,18 @@ if sys.version_info.major is 2:
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
elif sys.version_info.major is 3:
|
elif sys.version_info.major is 3:
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
|
|
||||||
|
def run_async(func):
|
||||||
|
from threading import Thread
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
@wraps(func)
|
||||||
|
def async_func(*args, **kwargs):
|
||||||
|
func_hl = Thread(target=func, args=args, kwargs=kwargs)
|
||||||
|
func_hl.start()
|
||||||
|
return func_hl
|
||||||
|
|
||||||
|
return async_func
|
||||||
|
|
||||||
class BotEventHandler(TelegramObject):
|
class BotEventHandler(TelegramObject):
|
||||||
"""
|
"""
|
||||||
|
@ -88,7 +100,8 @@ class BotEventHandler(TelegramObject):
|
||||||
self.update_queue.put(update)
|
self.update_queue.put(update)
|
||||||
self.last_update_id = update.update_id + 1
|
self.last_update_id = update.update_id + 1
|
||||||
current_interval = poll_interval
|
current_interval = poll_interval
|
||||||
sleep(current_interval)
|
|
||||||
|
sleep(current_interval)
|
||||||
except TelegramError as te:
|
except TelegramError as te:
|
||||||
# Put the error into the update queue and let the Broadcaster
|
# Put the error into the update queue and let the Broadcaster
|
||||||
# broadcast it
|
# broadcast it
|
||||||
|
|
Loading…
Reference in a new issue