Skip to content

os.waitpid that never ends with "sh" library #512

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

Open
cym13 opened this issue Mar 22, 2015 · 3 comments
Open

os.waitpid that never ends with "sh" library #512

cym13 opened this issue Mar 22, 2015 · 3 comments
Labels

Comments

@cym13
Copy link

cym13 commented Mar 22, 2015

Hi,

Here is the stackstrace:

$ /usr/bin/bpython

bpython version 0.14.1 on top of Python 3.4.3 /usr/bin/python
>>> from sh import ls, cat
>>> ls()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/sh.py", line 769, in __call__
    return RunningCommand(cmd, call_args, stdin, stdout, stderr)
  File "/usr/lib/python3.4/site-packages/sh.py", line 330, in __init__
    self.wait()
  File "/usr/lib/python3.4/site-packages/sh.py", line 334, in wait
    self._handle_exit_code(self.process.wait())
  File "/usr/lib/python3.4/site-packages/sh.py", line 1152, in wait
    pid, exit_code = os.waitpid(self.pid, 0)
InterruptedError: [Errno 4] Interrupted system call
>>> cat("./test.py")
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/sh.py", line 769, in __call__
    return RunningCommand(cmd, call_args, stdin, stdout, stderr)
  File "/usr/lib/python3.4/site-packages/sh.py", line 330, in __init__
    self.wait()
  File "/usr/lib/python3.4/site-packages/sh.py", line 334, in wait
    self._handle_exit_code(self.process.wait())
  File "/usr/lib/python3.4/site-packages/sh.py", line 1152, in wait
    pid, exit_code = os.waitpid(self.pid, 0)
InterruptedError: [Errno 4] Interrupted system call

Each call to a function imported through sh never ends, the previous
exceptions were thrown only when I forced it to flush by resizing the window.
The same lines were tested with python3 and ipython3 without problem.

It may be of importance to know my system:

$ uname -a
Linux Eather 3.19.2-1-ARCH #1 SMP PREEMPT Wed Mar 18 16:21:02 CET 2015 x86_64 GNU/Linux

@sebastinas sebastinas added the bug label Mar 22, 2015
@sebastinas
Copy link
Contributor

This might be a consequence of using greenlets. The old curses interface does not show this behavior.

@jquast
Copy link

jquast commented Feb 1, 2016

The same lines were tested with python3 and ipython3 without problem.

All python functions using system calls now gracefully retry when interrupted in python3.5, pep-475: https://www.python.org/dev/peps/pep-0475/

The only fix would be upstream sh.py module, to wrap os.waitpid with while True loop, continuing on InterruptedError, breaking otherwise.

@jquast
Copy link

jquast commented Feb 1, 2016

Also window resizes cause a signal (SIGWINCH), this is why os.waitpid is interrupted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants