CChildHarbor
Workflows

Coding workflows · Timed Python child execution

03
Built around your work

A concrete starting point

Run trusted Python text of at most 4096 characters in an existing directory with a 50–5000 ms timeout. Check Unicode output, failed exits and direct-child termination on timeout, rejecting invalid limits without claiming sandboxing or descendant cleanup.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Timed Python child execution

A concrete starting point
import math, os, subprocess, sys
from pathlib import Path

def run_trusted_python(script, seconds, folder):
    if type(script) is not str or len(script) > 4096:
        raise ValueError("child.script")
    if type(seconds) not in (int, float) or not .05 <= seconds <= 5 or not math.isfinite(seconds):
        raise ValueError("child.timeout")
    if not isinstance(folder, (str, Path)) or not Path(folder).is_dir():
        raise ValueError("child.folder")
    return subprocess.run([sys.executable, "-I", "-S", "-X", "utf8", "-c", script],
        cwd=folder, timeout=seconds, capture_output=True, text=True,
        encoding="utf-8", check=False,
        creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0)

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗