From 1c959357549a317309eed111bb5749f3d8d03de9 Mon Sep 17 00:00:00 2001 From: phi Date: Sat, 2 Mar 2024 06:47:40 +0900 Subject: [PATCH] fix: use self --- src/timeout_executor/terminate.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/timeout_executor/terminate.py b/src/timeout_executor/terminate.py index bebcf77..920a409 100644 --- a/src/timeout_executor/terminate.py +++ b/src/timeout_executor/terminate.py @@ -86,7 +86,7 @@ def _start_terminator_thread(self) -> None: logger.debug("%r create terminator thread", self) self._terminator_thread = threading.Thread( target=terminate, - args=(self.callback_args.process, self), + args=(self,), name=f"{self.func_name}-callback-{self.executor_args.executor.unique_id}", ) self._terminator_thread.daemon = True @@ -99,7 +99,7 @@ def _start_callback_thread(self) -> None: logger.debug("%r create callback thread", self) self._callback_thread = threading.Thread( target=callback, - args=(self.callback_args, self), + args=(self,), name=f"{self.func_name}-terminator-{self.executor_args.executor.unique_id}", ) self._callback_thread.daemon = True @@ -155,16 +155,16 @@ def remove_callback(self, callback: ProcessCallback) -> Self: return self -def terminate(process: subprocess.Popen[str], terminator: Terminator) -> None: +def terminate(terminator: Terminator) -> None: try: with suppress(TimeoutError, subprocess.TimeoutExpired): - process.wait(terminator.timeout) + terminator.callback_args.process.wait(terminator.timeout) finally: terminator.close("terminator thread") -def callback(callback_args: CallbackArgs, terminator: Terminator) -> None: +def callback(terminator: Terminator) -> None: try: - callback_args.process.wait() + terminator.callback_args.process.wait() finally: - terminator.run_callbacks(callback_args, terminator.func_name) + terminator.run_callbacks(terminator.callback_args, terminator.func_name)