Giter Site home page Giter Site logo

Comments (5)

srfoster65 avatar srfoster65 commented on June 2, 2024 2

Sure, I will create a PR.
This will be my first PR, so I hope I get things right.

from pdm.

srfoster65 avatar srfoster65 commented on June 2, 2024

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.

srfoster65 avatar srfoster65 commented on June 2, 2024

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.

srfoster65 avatar srfoster65 commented on June 2, 2024

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.

frostming avatar frostming commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.