commit ae71c94712fc938e24015727cfc1614b3faf95f0 Author: Damian Johnson atagar@torproject.org Date: Fri Sep 28 13:08:20 2018 -0700
Name background threads
When our tests fail to clean up their threads it's a pita to figure out what they are. Naming the background test runners.
Threads lingering after test run: <_MainThread(MainThread, started 139931129755392)> <Thread(Background test of test.integ.descriptor.networkstatus.test_cached_consensus, started daemon 139931063748352)> <Thread(Background test of test.integ.descriptor.microdescriptor.test_cached_microdescriptors, started daemon 139930965632768)> <Thread(Background test of test.integ.descriptor.server_descriptor.test_cached_descriptor, started daemon 139930974025472)> <Thread(Background test of test.integ.descriptor.networkstatus.test_cached_microdesc_consensus, started daemon 139931055355648)> --- stem/control.py | 7 +++---- stem/descriptor/reader.py | 2 +- stem/descriptor/remote.py | 2 +- stem/util/test_tools.py | 12 ++++++++++-- 4 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/stem/control.py b/stem/control.py index 8982d2d1..2e893788 100644 --- a/stem/control.py +++ b/stem/control.py @@ -894,10 +894,9 @@ class BaseController(object):
for listener, spawn in self._status_listeners: if spawn: - name = '%s notification' % state args = (self, state, change_timestamp)
- notice_thread = threading.Thread(target = listener, args = args, name = name) + notice_thread = threading.Thread(target = listener, args = args, name = '%s notification' % state) notice_thread.setDaemon(True) notice_thread.start() self._state_change_threads.append(notice_thread) @@ -915,12 +914,12 @@ class BaseController(object):
with self._socket._get_send_lock(): if not self._reader_thread or not self._reader_thread.is_alive(): - self._reader_thread = threading.Thread(target = self._reader_loop, name = 'Tor Listener') + self._reader_thread = threading.Thread(target = self._reader_loop, name = 'Tor listener') self._reader_thread.setDaemon(True) self._reader_thread.start()
if not self._event_thread or not self._event_thread.is_alive(): - self._event_thread = threading.Thread(target = self._event_loop, name = 'Event Notifier') + self._event_thread = threading.Thread(target = self._event_loop, name = 'Event notifier') self._event_thread.setDaemon(True) self._event_thread.start()
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py index 40f5b71c..9889751b 100644 --- a/stem/descriptor/reader.py +++ b/stem/descriptor/reader.py @@ -386,7 +386,7 @@ class DescriptorReader(object): raise ValueError('Already running, you need to call stop() first') else: self._is_stopped.clear() - self._reader_thread = threading.Thread(target = self._read_descriptor_files, name='Descriptor Reader') + self._reader_thread = threading.Thread(target = self._read_descriptor_files, name='Descriptor reader') self._reader_thread.setDaemon(True) self._reader_thread.start()
diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py index 9547b59a..dbae3cdf 100644 --- a/stem/descriptor/remote.py +++ b/stem/descriptor/remote.py @@ -414,7 +414,7 @@ class Query(object): with self._downloader_thread_lock: if self._downloader_thread is None: self._downloader_thread = threading.Thread( - name = 'Descriptor Query', + name = 'Descriptor query', target = self._download_descriptors, args = (self.retries, self.timeout) ) diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py index 759c8238..21e4a89b 100644 --- a/stem/util/test_tools.py +++ b/stem/util/test_tools.py @@ -116,7 +116,7 @@ def skip(msg):
def asynchronous(func): test = stem.util.test_tools.AsyncTest(func) - ASYNC_TESTS['%s.%s' % (func.__module__, func.__name__)] = test + ASYNC_TESTS[test.name] = test return test.method
@@ -143,6 +143,8 @@ class AsyncTest(object): """
def __init__(self, runner, args = None, threaded = False): + self.name = '%s.%s' % (runner.__module__, runner.__name__) + self._runner = runner self._runner_args = args self._threaded = threaded @@ -186,7 +188,13 @@ class AsyncTest(object): self._process_pipe, child_pipe = multiprocessing.Pipe()
if self._threaded: - self._process = threading.Thread(target = _wrapper, args = (child_pipe, self._runner, self._runner_args)) + self._process = threading.Thread( + target = _wrapper, + args = (child_pipe, self._runner, self._runner_args), + name = 'Background test of %s' % self.name, + ) + + self._process.setDaemon(True) else: self._process = multiprocessing.Process(target = _wrapper, args = (child_pipe, self._runner, self._runner_args))