Skip to content

Commit

Permalink
move setup and cleanup specific to ContainerizedTool
Browse files Browse the repository at this point in the history
The setup function now takes the config as argument as well.
  • Loading branch information
ricffb committed Dec 11, 2024
1 parent 374f90b commit b519960
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions benchexec/containerized_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,28 @@ def __init__(self, tool_module, config):
# We use multiprocessing.Pool as an easy way for RPC with another process.
self._pool = multiprocessing.Pool(1, _init_worker_process)

self.container_options = containerexecutor.handle_basic_container_args(config)
self.temp_dir = tempfile.mkdtemp(prefix="Benchexec_tool_info_container_")

# Call function that loads tool module and returns its doc
try:
self._setup_container(tool_module)

self._setup_container(tool_module, config)
except BaseException as e:
self._pool.terminate()
raise e

def _setup_container(self, tool_module, config):
container_options = containerexecutor.handle_basic_container_args(config)
temp_dir = tempfile.mkdtemp(prefix="Benchexec_tool_info_container_")

try:
self.__doc__, _ = self._pool.apply(
_init_container_and_load_tool,
[_init_container, tool_module, self.temp_dir],
container_options,
)
finally:
# Outside the container, the temp_dir is just an empty directory, because
# the tmpfs mount is only visible inside. We can remove it immediately.
with contextlib.suppress(OSError):
os.rmdir(self.temp_dir)

def _setup_container(self, tool_module):
self.__doc__, _ = self._pool.apply(
_init_container_and_load_tool,
[_init_container, tool_module, self.temp_dir],
self.container_options,
)
os.rmdir(temp_dir)

def close(self):
self._forward_call("close", [], {})
Expand Down
2 changes: 1 addition & 1 deletion contrib/vcloud/podman_containerized_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(self, tool_module, config, image):

super().__init__(tool_module, config)

def _setup_container(self, tool_module):
def _setup_container(self, tool_module, config):
self.__doc__, self.container_id = self._pool.apply(
_init_container_and_load_tool,
[_init_container, tool_module],
Expand Down

0 comments on commit b519960

Please sign in to comment.