From 3608c2bbe5151fe055f89d035ea2b67b16df8eac Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Wed, 1 Jun 2016 21:21:24 +0300 Subject: [PATCH] dispatcher: if connection pool is already initialized raise exception this will better protect the user from wrong usage --- telegram/ext/dispatcher.py | 7 +++++-- telegram/utils/request.py | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/telegram/ext/dispatcher.py b/telegram/ext/dispatcher.py index 85180a2db..31404501a 100644 --- a/telegram/ext/dispatcher.py +++ b/telegram/ext/dispatcher.py @@ -24,6 +24,8 @@ from threading import Thread, Lock, Event, current_thread from time import sleep from queue import Queue, Empty +from future.builtins import range + from telegram import (TelegramError, NullHandler) from telegram.utils import request from telegram.ext.handler import Handler @@ -109,8 +111,9 @@ class Dispatcher(object): self.__exception_event = exception_event or Event() if not len(ASYNC_THREADS): - if request._CON_POOL: - self.logger.warning("Connection Pool already initialized!") + if request.is_con_pool_initialized(): + raise RuntimeError('Connection Pool already initialized') + request.CON_POOL_SIZE = workers + 3 for i in range(workers): thread = Thread(target=_pooled, name=str(i)) diff --git a/telegram/utils/request.py b/telegram/utils/request.py index 4b923df4b..f43482747 100644 --- a/telegram/utils/request.py +++ b/telegram/utils/request.py @@ -47,6 +47,9 @@ def _get_con_pool(): ]) return _CON_POOL +def is_con_pool_initialized(): + return _CON_POOL is not None + def _parse(json_data): """Try and parse the JSON returned from Telegram.