-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
pdm run does not catch ctrl-c on 2nd run (Win11) #2292
Comments
Something very odd is happening here. Almost certainly windows specific. The issue is in the file pdm\cli\commands\run.py and function _run_process(). If I simplify the code in _run_process() (This is not a solution, but an attempt to understand program flow) and remove the signal handler function and replace with a try/except block.
This works everytime. Note: this is sending signal.SIGINT to the subporocess. If I modify the existing forward_signal() function
This will raise everytime, but will abort the script. But why should this raise a ValueError when calling send_signal() in the exception handler with the same value (signal.SIGINT = 2) does not? |
https://docs.python.org/3/library/signal.html#signal.CTRL_C_EVENT signal.CTRL_C_EVENT So the code in forward signal should not work as intended, and may partially explain the observed behaviour. |
A solution I found on stackoverflow that was used for a similar issue on postgress was to use signum=signal.SIGTERM for windows.
I have tested this and this seems to reliably terminate the subprocess. |
This seems to fix the issue without causing any other problems though TBH, I was unable to reproduce it. Would you or @xzmeng like to send a PR? |
Sure, I will create a PR. |
Steps to reproduce
Given a project that is setup to support mkdocs for generating documentation.
From a windows command shell (cmd), cd to the project root and enter the following commands
pdm run mkdocs serve
[ctrl-c] - To terminate serve process - this works correctly.
pdm run mkdocs serve
[ctrl-c] - Does not interrupt/terminate process
Note:
I have tested the same project with poetry, and this can repeatedly start and stop mkdocs serve with the command "poetry run mkdocs serve".
Actual behaviour
mkdocs serve process continues to run.
Expected behaviour
mkdocs serve process should be interrupted
Environment Information
pdm info
PDM version:
2.9.3
Python Interpreter:
C:\Users\Steve\Development\python\arg_init.venv\Scripts\python.exe (3.11)
Project Root:
C:/Users/Steve/Development/python/arg_init
Local Packages:
{
"implementation_name": "cpython",
"implementation_version": "3.11.3",
"os_name": "nt",
"platform_machine": "AMD64",
"platform_release": "10",
"platform_system": "Windows",
"platform_version": "10.0.22621",
"python_full_version": "3.11.3",
"platform_python_implementation": "CPython",
"python_version": "3.11",
"sys_platform": "win32"
}
The text was updated successfully, but these errors were encountered: