From 78f9bdcac906d0cfdd633321b647095af4eab373 Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Wed, 1 Jun 2016 21:05:34 +0300 Subject: [PATCH] dispatcher: pep8 style fix globals are supposed to be upper case --- telegram/ext/dispatcher.py | 20 ++++++++++---------- telegram/ext/updater.py | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/telegram/ext/dispatcher.py b/telegram/ext/dispatcher.py index bd4151721..e71fedf45 100644 --- a/telegram/ext/dispatcher.py +++ b/telegram/ext/dispatcher.py @@ -31,24 +31,24 @@ from telegram.utils.deprecate import deprecate logging.getLogger(__name__).addHandler(NullHandler()) -async_queue = Queue() -async_threads = set() +ASYNC_QUEUE = Queue() +ASYNC_THREADS = set() """:type: set[Thread]""" -async_lock = Lock() +ASYNC_LOCK = Lock() DEFAULT_GROUP = 0 -def pooled(): +def _pooled(): """ A wrapper to run a thread in a thread pool """ while True: try: - func, args, kwargs = async_queue.get() + func, args, kwargs = ASYNC_QUEUE.get() except TypeError: logging.debug("Closing run_async thread %s/%d" % - (current_thread().getName(), len(async_threads))) + (current_thread().getName(), len(ASYNC_THREADS))) break try: @@ -77,7 +77,7 @@ def run_async(func): """ A wrapper to run a function in a thread """ - async_queue.put((func, pargs, kwargs)) + ASYNC_QUEUE.put((func, pargs, kwargs)) return async_func @@ -108,13 +108,13 @@ class Dispatcher(object): self.__stop_event = Event() self.__exception_event = exception_event or Event() - if not len(async_threads): + if not len(ASYNC_THREADS): if request._CON_POOL: self.logger.warning("Connection Pool already initialized!") request.CON_POOL_SIZE = workers + 3 for i in range(workers): - thread = Thread(target=pooled, name=str(i)) - async_threads.add(thread) + thread = Thread(target=_pooled, name=str(i)) + ASYNC_THREADS.add(thread) thread.start() else: self.logger.debug('Thread pool already initialized, skipping.') diff --git a/telegram/ext/updater.py b/telegram/ext/updater.py index 2f92fe43f..cba48aaf6 100644 --- a/telegram/ext/updater.py +++ b/telegram/ext/updater.py @@ -372,12 +372,12 @@ class Updater(object): self.dispatcher.stop() def _join_async_threads(self): - with dispatcher.async_lock: - threads = list(dispatcher.async_threads) + with dispatcher.ASYNC_LOCK: + threads = list(dispatcher.ASYNC_THREADS) total = len(threads) for i in range(total): - dispatcher.async_queue.put(0) + dispatcher.ASYNC_QUEUE.put(0) for i, thr in enumerate(threads): self.logger.debug('Waiting for async thread {0}/{1} to end'.format(i, total))