question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pipx run isn't redirecting signals to child app (?)

See original GitHub issue

Hello,

What a wonderful tool, no more manual management of python apps in my system 😃

About the issue, I wonder if signals are being redirected to the child app when calling pipx run <app>. For instance:

pipx run --spec tmonpy tmon

tmon in the absence of arguments, waits for SIGINT to return and print a temperature report. But it looks like pipx run when SIGINT-ed kills the app and doesn’t give it a chance to return gracefully (I could be wrong though, I haven’t looked at the source).

So this is what I would expect to happen:

pipx run --spec tmonpy tmon

wait a few seconds, press Ctrl+C and a graph should be printed in the terminal:

===================
Temp Monitor Report

    temp (°C) for a period of 0:00:04
       41.00  ┤
       40.86  ┤
       40.71  ┤
       40.57  ┤
       40.43  ┤
       40.29  ┤
       40.14  ┤
       40.00  ┼╮
       39.86  ┤│
       39.71  ┤│
       39.57  ┤│
       39.43  ┤│
       39.29  ┤│
       39.14  ┤│
       39.00  ┤╰───

    min: 39.1 °C
    avg: 39.2 °C
    max: 40.0 °C

    raw: /tmp/tmon-20200926@19h56m17-c1jxq4s6.txt
===================

Note: tmon is expected to work on Linux only! Don’t try to run the test case on mac or win.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
uranusjrcommented, Oct 15, 2020

I couldn’t find any good documentation on why, however. ox.exec* lists availability on Windows. @uranusjr, why do you need to fall back to subprocess for Windows?

Do we just need to use our original code for Windows? Or is there an advantage to how pipenv does things with subprocess.Popen(), etc.?

Windows and Unix-like systems implement exec* stuff differently. On POSIX, the process is first forked, and then the new program is loaded into the (forked) process. Windows does not have fork, so the implementation basically starts a new process in the background, and exits the current process. This is fine for Windows (the subsystem, not the operating system) applications, but has some unexpected (to people familiar with the fork-based implementation) behaviours when used in the console subsystem. You can try this in cmd.exe:

C:\>py -c "import os, sys; os.execl(sys.executable, 'python', '-V')"

C:\>Python 3.9.0

You can see a prompt being displayed before the version information, because the process launched with os.execl is in the background, and you get dropped back to the shell when the former process exits. This causes more problems when you need to interact with the launched process:

C:\>py -c "import os, sys; os.execl(sys.executable, 'python', '-q')"

C:\>>>> import sys
'import' is not recognized as an internal or external command,
operable program or batch file.

Since the new process is in the background, and the user is dropped back to the shell, all inputs now goes to the shell, not the launched process.

Rule of thumb: Don’t use the exec* family on Windows in a console application. It never does what you want.

1reaction
uranusjrcommented, Oct 14, 2020

os.exec* (which calls into the corresponding exec* C functions) “swaps out” the current process entirely, so the current process (which is running pytest) just vanishes in thin air when you call that. This is done at the OS level, thus not possible to verify with pytest. The best thing you can do is to mock it out and verify the arguments.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pipx run isn't redirecting signals to child app (?) #506 - GitHub
We use subprocess.run() to run your pipx run script, and we do not supply a stdin argument, which should mean that stdin is...
Read more >
pipx — Install and Run Python Applications in Isolated ...
If so, go to the mentioned folder, allowing you to run the pipx executable directly. Enter the following line (even if you did...
Read more >
How to redirect signal to child process from parent process?
Try it in a shell - start some process, then press Ctrl-Z. Now hit fg and enter - the process will continue where...
Read more >
pybind11 Documentation - Read the Docs
pybind11 is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python.
Read more >
TS 133 501 - V16.9.1 - 5G - ETSI
The content of the PDF version shall not be modified without the written authorization of ETSI. ... Rules on concurrent running of security...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found