MCPcopy Create free account
hub / github.com/catid/supercharger / execute

Method execute

codegen/docker_execute.py:44–75  ·  view source on GitHub ↗
(self, script_filename=None, command=None, timeout=10)

Source from the content-addressed store, hash-verified

42
43 # Execute a command under `sources` that depends on the given script. By default it runs the given script.
44 def execute(self, script_filename=None, command=None, timeout=10):
45 try:
46 if self.container is None:
47 self.recreate_container()
48
49 # Define a signal handler for the timeout
50 def handler(signum, frame):
51 raise TimeoutError("Execution timed out")
52
53 # Set a signal alarm to raise a TimeoutError after 30 seconds
54 signal.signal(signal.SIGALRM, handler)
55 signal.alarm(timeout)
56
57 if command is None:
58 command = f"python {script_filename}"
59
60 # Run the test code in the existing container
61 exit_code, output = self.container.exec_run(
62 command,
63 workdir=f"/{self.sources_dirname}",
64 )
65
66 # Disable the signal alarm after the code has finished executing
67 signal.alarm(0)
68
69 logs = output.decode("utf-8").strip()
70
71 return exit_code, logs
72
73 except Exception as e:
74 self.shutdown()
75 return -1, ""

Callers 4

mainFunction · 0.95
benchmark_docker_executeFunction · 0.95
copy_and_run_pytestFunction · 0.80

Calls 2

recreate_containerMethod · 0.95
shutdownMethod · 0.95

Tested by 2

mainFunction · 0.76
benchmark_docker_executeFunction · 0.76