Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use finally to terminate parallel processes #10952

Merged
merged 1 commit into from
Jan 2, 2023

Conversation

pmeier
Copy link
Contributor

@pmeier pmeier commented Nov 2, 2022

Subject: Correctly terminate parallel processes.

Feature or Bugfix

  • Feature

Purpose

While debugging an issue with parallel docs building, I encountered zombie parallel processes. This happened after I used ctrl+c to stop a hanging build. With this change, all parallel process will be terminated correctly regardless of the reason that terminated the build.

Detail

The reason is simple: except Exception does not catch everything. For example, KeyboardInterrupt which is raised through ctrl+c will not be caught:

try:
    raise KeyboardInterrupt
except Exception:
    print("Terminating processes", flush=True)
    raise
Traceback (most recent call last):
  File "/home/user/main.py", line 2, in <module>
    raise KeyboardInterrupt
KeyboardInterrupt

See the exception hierarchy for details.

Since we don't do anything with the caught exception other than re-raising it, we can simply use the finally clause:

try:
    raise KeyboardInterrupt
finally:
    print("Terminating processes", flush=True)
Terminating processes
Traceback (most recent call last):
  File "/home/user/main.py", line 2, in <module>
    raise KeyboardInterrupt
KeyboardInterrupt

@AA-Turner AA-Turner changed the title use finally to terminate parallel processes Use finally to terminate parallel processes Jan 2, 2023
@AA-Turner AA-Turner merged commit 6037ec3 into sphinx-doc:master Jan 2, 2023
@pmeier pmeier deleted the parallel-terminate branch January 2, 2023 11:17
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants