Fix orphaned simulator processes on Ctrl+C or task failure#1427
Open
Jjateen wants to merge 7 commits intoriscv:act4from
Open
Fix orphaned simulator processes on Ctrl+C or task failure#1427Jjateen wants to merge 7 commits intoriscv:act4from
Jjateen wants to merge 7 commits intoriscv:act4from
Conversation
When a task failed early (keep_going=False) or the user pressed Ctrl+C, any sail_riscv_sim processes already launched by ThreadPoolExecutor worker threads were left alive. Workers blocked in proc.communicate() kept the executor alive and the simulator ran indefinitely. Three fixes in build.py: - Switch SubprocessAction execution from subprocess.run() to Popen with start_new_session=True so each simulator gets its own process group, allowing os.killpg() to reach any children it spawns. - Add _ProcTracker, a thread-safe registry of running process group IDs. Workers register their pgid on launch and deregister on completion. A shutting_down flag ensures late-registrants (processes that start after kill_all() is called) are killed immediately on add(). - Call tracker.kill_all() on early task failure (before executor shutdown) and in a try/finally so cleanup runs on Ctrl+C or any other exception. A SIGINT handler also calls kill_all() to terminate simulators before ThreadPoolExecutor waits for worker threads to join. Fixes riscv#1238.
9e07973 to
a04e0dc
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates ACT’s Python DAG build executor to prevent orphaned sail_riscv_sim (and child) processes when the run is interrupted (Ctrl+C) or stops early due to a task failure with keep_going=False.
Changes:
- Run
SubprocessActioncommands viasubprocess.Popen(..., start_new_session=True)and track process-group IDs for group termination. - Add a thread-safe
_ProcTrackerto register/deregister running subprocess PGIDs and kill them on shutdown. - Ensure cleanup runs on early failure and via a SIGINT handler /
try/finallykill path.
d032af3 to
c627e38
Compare
0d9151a to
151eb9c
Compare
90f6b7b to
9bd0f3e
Compare
Contributor
Author
|
@jordancarlin can you review/approve this further? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a task failed early (keep_going=False) or the user pressed Ctrl+C, any sail_riscv_sim processes already launched by ThreadPoolExecutor worker threads were left alive. Workers blocked in proc.communicate() kept the executor alive and the simulator ran indefinitely.
Three fixes in build.py:
Fixes #1238.