Skip to content

Commit

Permalink
fix: initfile args
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Sep 13, 2024
1 parent 3b21ce8 commit 6e5f9b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/timeout_executor/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def _create_executor_args(
self,
input_file: Path | anyio.Path,
output_file: Path | anyio.Path,
init_file: Path | anyio.Path | None,
terminator: Terminator[P, T],
) -> ExecutorArgs[P, T]:
"""create executor args"""
Expand All @@ -149,6 +150,7 @@ def _create_executor_args(
terminator=terminator,
input_file=input_file,
output_file=output_file,
init_file=init_file,
timeout=self._timeout,
)

Expand Down Expand Up @@ -177,7 +179,7 @@ def _init_process(
"""
logger.debug("%r before init process", self, stacklevel=stacklevel)
executor_args_builder = partial(
self._create_executor_args, input_file, output_file
self._create_executor_args, input_file, output_file, init_file
)
terminator = Terminator(executor_args_builder, self.callbacks)
process = self._create_process(input_file, init_file, stacklevel=stacklevel + 1)
Expand Down
6 changes: 5 additions & 1 deletion src/timeout_executor/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ def __init__(
self._executor_args = executor_args
self._result = SENTINEL

input_file, output_file = (
input_file, output_file, init_file = (
self._executor_args.input_file,
self._executor_args.output_file,
self._executor_args.init_file,
)
self._input = anyio.Path(input_file)
self._output = anyio.Path(output_file)
self._init = None if init_file is None else anyio.Path(init_file)

@property
def _func_name(self) -> str:
Expand Down Expand Up @@ -119,6 +121,8 @@ async def _load_output(self) -> T:
async with anyio.create_task_group() as task_group:
task_group.start_soon(self._output.unlink, True) # noqa: FBT003
task_group.start_soon(self._input.unlink, True) # noqa: FBT003
if self._init is not None:
task_group.start_soon(self._init.unlink, True) # noqa: FBT003
await self._output.parent.rmdir()
return await self._load_output()

Expand Down
2 changes: 2 additions & 0 deletions src/timeout_executor/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class ExecutorArgs(Generic[P, T]):
"""function args input file"""
output_file: Path | anyio.Path
"""function result output file"""
init_file: Path | anyio.Path | None
"""initializer file"""
timeout: float
"""timeout"""

Expand Down

0 comments on commit 6e5f9b9

Please sign in to comment.