Skip to content

Commit

Permalink
fix: use self
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Mar 1, 2024
1 parent c504c23 commit 1c95935
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/timeout_executor/terminate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 1c95935

Please sign in to comment.