Merge remote-tracking branch 'origin/V12'

This commit is contained in:
Noam Meltzer 2019-08-24 01:04:10 +03:00
commit 79dc6edf25
5 changed files with 16 additions and 5 deletions

View file

@ -166,7 +166,8 @@ class Dispatcher(object):
base_name = '{}_'.format(base_name) if base_name else ''
for i in range(workers):
thread = Thread(target=self._pooled, name='{}{}'.format(base_name, i))
thread = Thread(target=self._pooled, name='Bot:{}:worker:{}{}'.format(self.bot.id,
base_name, i))
self.__async_threads.add(thread)
thread.start()

View file

@ -287,7 +287,8 @@ class JobQueue(object):
if not self._running:
self._running = True
self.__start_lock.release()
self.__thread = Thread(target=self._main_loop, name="job_queue")
self.__thread = Thread(target=self._main_loop,
name="Bot:{}:job_queue".format(self._dispatcher.bot.id))
self.__thread.start()
self.logger.debug('%s thread started', self.__class__.__name__)
else:

View file

@ -157,7 +157,8 @@ class Updater(object):
self.__threads = []
def _init_thread(self, target, name, *args, **kwargs):
thr = Thread(target=self._thread_wrapper, name=name, args=(target,) + args, kwargs=kwargs)
thr = Thread(target=self._thread_wrapper, name="Bot:{}:{}".format(self.bot.id, name),
args=(target,) + args, kwargs=kwargs)
thr.start()
self.__threads.append(thr)

View file

@ -384,6 +384,12 @@ class TestDispatcher(object):
sleep(.1)
assert self.received == 'Unauthorized.'
def test_sensible_worker_thread_names(self, dp2):
thread_names = [thread.name for thread in getattr(dp2, '_Dispatcher__async_threads')]
print(thread_names)
for thread_name in thread_names:
assert thread_name.startswith("Bot:{}:worker:".format(dp2.bot.id))
@pytest.mark.skipif(sys.version_info < (3, 0), reason='pytest fails this for no reason')
def test_non_context_deprecation(self, dp):
with pytest.warns(TelegramDeprecationWarning):

View file

@ -111,8 +111,10 @@ class TestUpdater(object):
# NOTE: Checking Updater.running is problematic because it is not set to False when there's
# an unhandled exception.
# TODO: We should have a way to poll Updater status and decide if it's running or not.
assert any('unhandled exception in updater' in rec.getMessage() for rec in
caplog.get_records('call'))
import pprint
pprint.pprint([rec.getMessage() for rec in caplog.get_records('call')])
assert any('unhandled exception in Bot:{}:updater'.format(updater.bot.id) in
rec.getMessage() for rec in caplog.get_records('call'))
@pytest.mark.parametrize(('error',),
argvalues=[(RetryAfter(0.01),),