mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-22 07:06:26 +01:00
dispatcher: if connection pool is already initialized raise exception
this will better protect the user from wrong usage
This commit is contained in:
parent
c28763c5be
commit
3608c2bbe5
2 changed files with 8 additions and 2 deletions
|
@ -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))
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue