|
31 | 31 |
|
32 | 32 | logging.getLogger(__name__).addHandler(NullHandler())
|
33 | 33 |
|
34 |
| -async_queue = Queue() |
35 |
| -async_threads = set() |
| 34 | +ASYNC_QUEUE = Queue() |
| 35 | +ASYNC_THREADS = set() |
36 | 36 | """:type: set[Thread]"""
|
37 |
| -async_lock = Lock() |
| 37 | +ASYNC_LOCK = Lock() |
38 | 38 | DEFAULT_GROUP = 0
|
39 | 39 |
|
40 | 40 |
|
41 |
| -def pooled(): |
| 41 | +def _pooled(): |
42 | 42 | """
|
43 | 43 | A wrapper to run a thread in a thread pool
|
44 | 44 | """
|
45 | 45 | while True:
|
46 | 46 | try:
|
47 |
| - func, args, kwargs = async_queue.get() |
| 47 | + func, args, kwargs = ASYNC_QUEUE.get() |
48 | 48 |
|
49 | 49 | except TypeError:
|
50 | 50 | logging.debug("Closing run_async thread %s/%d" %
|
51 |
| - (current_thread().getName(), len(async_threads))) |
| 51 | + (current_thread().getName(), len(ASYNC_THREADS))) |
52 | 52 | break
|
53 | 53 |
|
54 | 54 | try:
|
@@ -77,7 +77,7 @@ def async_func(*pargs, **kwargs):
|
77 | 77 | """
|
78 | 78 | A wrapper to run a function in a thread
|
79 | 79 | """
|
80 |
| - async_queue.put((func, pargs, kwargs)) |
| 80 | + ASYNC_QUEUE.put((func, pargs, kwargs)) |
81 | 81 |
|
82 | 82 | return async_func
|
83 | 83 |
|
@@ -108,13 +108,13 @@ def __init__(self, bot, update_queue, workers=4, exception_event=None):
|
108 | 108 | self.__stop_event = Event()
|
109 | 109 | self.__exception_event = exception_event or Event()
|
110 | 110 |
|
111 |
| - if not len(async_threads): |
| 111 | + if not len(ASYNC_THREADS): |
112 | 112 | if request._CON_POOL:
|
113 | 113 | self.logger.warning("Connection Pool already initialized!")
|
114 | 114 | request.CON_POOL_SIZE = workers + 3
|
115 | 115 | for i in range(workers):
|
116 |
| - thread = Thread(target=pooled, name=str(i)) |
117 |
| - async_threads.add(thread) |
| 116 | + thread = Thread(target=_pooled, name=str(i)) |
| 117 | + ASYNC_THREADS.add(thread) |
118 | 118 | thread.start()
|
119 | 119 | else:
|
120 | 120 | self.logger.debug('Thread pool already initialized, skipping.')
|
|
0 commit comments