Comments (5)
Sure, I will create a PR.
This will be my first PR, so I hope I get things right.
from pdm.
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.
try:
process = subprocess.Popen(expanded_args, cwd=cwd, env=process_env, shell=shell, bufsize=0)
process.wait()
except KeyboardInterrupt:
process.send_signal(signal.SIGINT)
This works everytime. Note: this is sending signal.SIGINT to the subporocess.
If I modify the existing forward_signal() function
def forward_signal(signum: int, frame: FrameType | None) -> None:
process.send_signal(signum)
This will raise
[ValueError]: Unsupported signal: 2
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?
from pdm.
https://docs.python.org/3/library/signal.html#signal.CTRL_C_EVENT
signal.CTRL_C_EVENT
The signal corresponding to the Ctrl+C keystroke event. This signal can only be used with os.kill().
So the code in forward signal should not work as intended, and may partially explain the observed behaviour.
from pdm.
A solution I found on stackoverflow that was used for a similar issue on postgress was to use signum=signal.SIGTERM for windows.
def forward_signal(signum: int, frame: FrameType | None) -> None:
if sys.platform == "win32" and signum == signal.SIGINT:
signum = signal.SIGTERM
process.send_signal(signum)
I have tested this and this seems to reliably terminate the subprocess.
from pdm.
A solution I found on stackoverflow that was used for a similar issue on postgress was to use signum=signal.SIGTERM for windows.
def forward_signal(signum: int, frame: FrameType | None) -> None: if sys.platform == "win32" and signum == signal.SIGINT: signum = signal.SIGTERM process.send_signal(signum)
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?
from pdm.
Related Issues (20)
- Central installation cache packages duplicated in local Windows project HOT 3
- Option to update specific sub-dependency in lock file HOT 3
- PDM sync does not handle local versions properly HOT 1
- Redundant download optimization HOT 2
- pdm venv create succeeds/fails alternately HOT 2
- Getting faustratied due to infinite resolutin loops. HOT 2
- lock --check with direct_minimal_versions constraint HOT 1
- Config-settings option for `pdm install` command HOT 2
- [FR] Lock entry for `foo[bar,qux]`: tell which deps come from `bar` vs. `qux` HOT 1
- `dev-dependencies` are not being added to `pyproject.toml` when `tool.pdm.source` is present. HOT 1
- [Monorepo] index has to be set twice HOT 1
- Drop `#egg` fragment on `pdm export` if supplied a `--no-egg-fragments` HOT 3
- Default values for CLI arguments not aligned with documentation HOT 1
- pdm install won't install local development package HOT 3
- Repository configuration not possible at project level
- ImportError: pip is not installed HOT 4
- Local path is not installable for non-selected dev dependency HOT 4
- comma in Author name makes publishing to PyPI impossible HOT 1
- Add `requires-pdm` option in pyproject.toml like `requires-python` HOT 12
- bug fix report, binaries of wrong "32/64" bitnes in __pypackages__ HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdm.