Download testbed/Textualize__textual/e2e_tests/sandbox_basic_test.py from hc99/FEA-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/datasets/hc99/FEA-Bench/resolve/main/testbed/Textualize__textual/e2e_tests/sandbox_basic_test.py
- Command line
-
hf download hf://datasets/hc99/FEA-Bench/testbed/Textualize__textual/e2e_tests/sandbox_basic_test.py
-
curl -L -o sandbox_basic_test.py https://huggingface.co/datasets/hc99/FEA-Bench/resolve/main/testbed/Textualize__textual/e2e_tests/sandbox_basic_test.py
1.48 kB
| from __future__ import annotations | |
| import shlex | |
| import sys | |
| import subprocess | |
| import threading | |
| from pathlib import Path | |
| target_script_name = "basic" | |
| script_time_to_live = 2.0 # in seconds | |
| if len(sys.argv) > 1: | |
| target_script_name = sys.argv[1] | |
| if len(sys.argv) > 2: | |
| script_time_to_live = float(sys.argv[2]) | |
| e2e_root = Path(__file__).parent / "test_apps" | |
| completed_process = None | |
| def launch_sandbox_script(python_file_name: str) -> None: | |
| global completed_process | |
| command = f"{sys.executable} {shlex.quote(python_file_name)}.py" | |
| print(f"Launching command '{command}'...") | |
| try: | |
| completed_process = subprocess.run( | |
| command, shell=True, check=True, capture_output=True, cwd=str(e2e_root) | |
| ) | |
| except subprocess.CalledProcessError as err: | |
| print(f"Process error: {err.stderr}") | |
| raise | |
| thread = threading.Thread( | |
| target=launch_sandbox_script, args=(target_script_name,), daemon=False | |
| ) | |
| thread.start() | |
| print( | |
| f"Launching Python script in a sub-thread; we'll wait for it for {script_time_to_live} seconds..." | |
| ) | |
| thread.join(timeout=script_time_to_live) | |
| print("The wait is over.") | |
| process_still_running = completed_process is None | |
| process_was_able_to_run_without_errors = process_still_running | |
| if process_was_able_to_run_without_errors: | |
| print("Python script is still running :-)") | |
| else: | |
| print("Python script is no longer running :-/") | |
| sys.exit(0 if process_was_able_to_run_without_errors else 1) | |