commit 75f883864d9b68b11f8f2d1611a449c5ca9db063 Author: Damian Johnson atagar@torproject.org Date: Fri Aug 18 08:05:04 2017 -0700
Move testing to DaemonTask
Now that we vend running daemon tasks lets use it ourselves. :P --- stem/util/system.py | 3 +++ test/task.py | 17 ++--------------- 2 files changed, 5 insertions(+), 15 deletions(-)
diff --git a/stem/util/system.py b/stem/util/system.py index 6301c67b..e4b2d874 100644 --- a/stem/util/system.py +++ b/stem/util/system.py @@ -258,6 +258,9 @@ class DaemonTask(object): :raises: exception raised by the function if it failed with one """
+ if self.status == State.PENDING: + self.run() + if self.status == State.RUNNING: response = self._pipe.recv() self._process.join() diff --git a/test/task.py b/test/task.py index f764fe99..53606a19 100644 --- a/test/task.py +++ b/test/task.py @@ -23,7 +23,6 @@ """
import importlib -import multiprocessing import os import re import sys @@ -169,7 +168,6 @@ class Task(object):
self._is_background_task = background self._background_process = None - self._background_pipe = None
def run(self): start_time = time.time() @@ -180,14 +178,7 @@ class Task(object):
try: if self._is_background_task: - def _run_wrapper(conn, runner, args): - os.nice(15) - conn.send(runner(*args) if args else runner()) - conn.close() - - self._background_pipe, child_pipe = multiprocessing.Pipe() - self._background_process = multiprocessing.Process(target = _run_wrapper, args = (child_pipe, self.runner, self.args)) - self._background_process.start() + self._background_process = stem.util.system.DaemonTask(self.runner, self.args, start = True) else: self.result = self.runner(*self.args) if self.args else self.runner()
@@ -215,11 +206,7 @@ class Task(object):
def join(self): if self._background_process: - try: - self.result = self._background_pipe.recv() - self._background_process.join() - except IOError: - pass + self.result = self._background_process.join()
class ModuleVersion(Task):
tor-commits@lists.torproject.org