Skip to content

Commit 05abd35

Browse files
Refactor precheck command to improve process handling and Docker integration
- Changed the command to execute 'cf-precheck' using 'exec' for better process management. - Added '--init' flag to the Docker run command to improve signal handling. - Simplified error handling during precheck execution, ensuring proper termination of the process on user interruption or timeout. Made-with: Cursor
1 parent a495179 commit 05abd35

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

chipfoundry_cli/main.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,10 +3275,10 @@ def precheck(project_root, skip_checks, magic_drc, checks, dry_run):
32753275
if checks:
32763276
precheck_args.extend(list(checks))
32773277

3278-
inner_cmd = 'pip3 install --upgrade -q --root-user-action=ignore cf-precheck 2>/dev/null && cf-precheck ' + ' '.join(precheck_args)
3278+
inner_cmd = 'pip3 install --upgrade -q --root-user-action=ignore cf-precheck 2>/dev/null && exec cf-precheck ' + ' '.join(precheck_args)
32793279

32803280
docker_cmd = [
3281-
'docker', 'run', '--rm',
3281+
'docker', 'run', '--rm', '--init',
32823282
'-v', f'{project_root_path}:{project_root_path}',
32833283
'-v', f'{pdk_root}:{pdk_root}',
32843284
'-e', f'PDK_ROOT={pdk_root}',
@@ -3328,11 +3328,7 @@ def precheck(project_root, skip_checks, magic_drc, checks, dry_run):
33283328
console.print("[cyan]Running cf-precheck...[/cyan]\n")
33293329

33303330
try:
3331-
process = subprocess.Popen(
3332-
docker_cmd,
3333-
preexec_fn=os.setsid if os.name != 'nt' else None
3334-
)
3335-
3331+
process = subprocess.Popen(docker_cmd)
33363332
returncode = process.wait()
33373333

33383334
console.print("")
@@ -3348,17 +3344,11 @@ def precheck(project_root, skip_checks, magic_drc, checks, dry_run):
33483344
except KeyboardInterrupt:
33493345
console.print("\n[yellow]⚠[/yellow] Precheck interrupted by user")
33503346
try:
3351-
if os.name != 'nt':
3352-
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
3353-
process.wait(timeout=5)
3354-
else:
3355-
process.terminate()
3356-
process.wait(timeout=5)
3357-
except Exception:
3358-
if os.name != 'nt':
3359-
os.killpg(os.getpgid(process.pid), signal.SIGKILL)
3360-
else:
3361-
process.kill()
3347+
process.terminate()
3348+
process.wait(timeout=10)
3349+
except (subprocess.TimeoutExpired, Exception):
3350+
process.kill()
3351+
sys.exit(130)
33623352
except Exception as e:
33633353
console.print(f"\n[red]✗[/red] Error running precheck: {e}")
33643354

0 commit comments

Comments
 (0)