Run Configuration Timeout and Cancellation Signal Behavior
0 reputation · 27 Jan 2024, 18:47 UTC
PyCharm's Run Configuration includes a Timeout field designed to abort processes after a specified duration. While this terminates the primary process, the mechanism does not inherently guarantee the graceful interruption of background threads or asynchronous tasks, especially when the Python code does not explicitly handle signals.
The Stop/Cancel button dispatches SIGINT or SIGTERM to the subprocess. However, pending I/O operations or generator cleanup may persist if the application is not designed for cooperative cancellation. Additionally, the debugger does not surface a standardized exception to differentiate a forced timeout termination from a standard process exit.
What specific exit code is reported by the IDE when the Timeout field expires? Is there a configuration to ensure the Cancel button's signal is prioritized over blocking I/O? How can asyncio tasks be made to respect PyCharm's cancellation intent without altering the application source code?