mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-29 01:37:28 +01:00
dispatcher: pep8 style fix
globals are supposed to be upper case
This commit is contained in:
parent
1ff348adbb
commit
78f9bdcac9
2 changed files with 13 additions and 13 deletions
|
@ -31,24 +31,24 @@ from telegram.utils.deprecate import deprecate
|
||||||
|
|
||||||
logging.getLogger(__name__).addHandler(NullHandler())
|
logging.getLogger(__name__).addHandler(NullHandler())
|
||||||
|
|
||||||
async_queue = Queue()
|
ASYNC_QUEUE = Queue()
|
||||||
async_threads = set()
|
ASYNC_THREADS = set()
|
||||||
""":type: set[Thread]"""
|
""":type: set[Thread]"""
|
||||||
async_lock = Lock()
|
ASYNC_LOCK = Lock()
|
||||||
DEFAULT_GROUP = 0
|
DEFAULT_GROUP = 0
|
||||||
|
|
||||||
|
|
||||||
def pooled():
|
def _pooled():
|
||||||
"""
|
"""
|
||||||
A wrapper to run a thread in a thread pool
|
A wrapper to run a thread in a thread pool
|
||||||
"""
|
"""
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
func, args, kwargs = async_queue.get()
|
func, args, kwargs = ASYNC_QUEUE.get()
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
logging.debug("Closing run_async thread %s/%d" %
|
logging.debug("Closing run_async thread %s/%d" %
|
||||||
(current_thread().getName(), len(async_threads)))
|
(current_thread().getName(), len(ASYNC_THREADS)))
|
||||||
break
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -77,7 +77,7 @@ def run_async(func):
|
||||||
"""
|
"""
|
||||||
A wrapper to run a function in a thread
|
A wrapper to run a function in a thread
|
||||||
"""
|
"""
|
||||||
async_queue.put((func, pargs, kwargs))
|
ASYNC_QUEUE.put((func, pargs, kwargs))
|
||||||
|
|
||||||
return async_func
|
return async_func
|
||||||
|
|
||||||
|
@ -108,13 +108,13 @@ class Dispatcher(object):
|
||||||
self.__stop_event = Event()
|
self.__stop_event = Event()
|
||||||
self.__exception_event = exception_event or Event()
|
self.__exception_event = exception_event or Event()
|
||||||
|
|
||||||
if not len(async_threads):
|
if not len(ASYNC_THREADS):
|
||||||
if request._CON_POOL:
|
if request._CON_POOL:
|
||||||
self.logger.warning("Connection Pool already initialized!")
|
self.logger.warning("Connection Pool already initialized!")
|
||||||
request.CON_POOL_SIZE = workers + 3
|
request.CON_POOL_SIZE = workers + 3
|
||||||
for i in range(workers):
|
for i in range(workers):
|
||||||
thread = Thread(target=pooled, name=str(i))
|
thread = Thread(target=_pooled, name=str(i))
|
||||||
async_threads.add(thread)
|
ASYNC_THREADS.add(thread)
|
||||||
thread.start()
|
thread.start()
|
||||||
else:
|
else:
|
||||||
self.logger.debug('Thread pool already initialized, skipping.')
|
self.logger.debug('Thread pool already initialized, skipping.')
|
||||||
|
|
|
@ -372,12 +372,12 @@ class Updater(object):
|
||||||
self.dispatcher.stop()
|
self.dispatcher.stop()
|
||||||
|
|
||||||
def _join_async_threads(self):
|
def _join_async_threads(self):
|
||||||
with dispatcher.async_lock:
|
with dispatcher.ASYNC_LOCK:
|
||||||
threads = list(dispatcher.async_threads)
|
threads = list(dispatcher.ASYNC_THREADS)
|
||||||
total = len(threads)
|
total = len(threads)
|
||||||
|
|
||||||
for i in range(total):
|
for i in range(total):
|
||||||
dispatcher.async_queue.put(0)
|
dispatcher.ASYNC_QUEUE.put(0)
|
||||||
|
|
||||||
for i, thr in enumerate(threads):
|
for i, thr in enumerate(threads):
|
||||||
self.logger.debug('Waiting for async thread {0}/{1} to end'.format(i, total))
|
self.logger.debug('Waiting for async thread {0}/{1} to end'.format(i, total))
|
||||||
|
|
Loading…
Add table
Reference in a new issue