Skip to content
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

Monkey patching breaks usage of subprocess.TimeoutExpired in a virtual env #624

Open
dtantsur opened this issue Jul 6, 2020 · 2 comments

Comments

@dtantsur
Copy link
Contributor

dtantsur commented Jul 6, 2020

Reproducer (on Python 3.8 for me, also seems to reproduce on 3.6):

import eventlet
eventlet.monkey_patch()

import subprocess


try:
    subprocess.check_call('sleep 10', shell=True, timeout=1)
except subprocess.TimeoutExpired:
    print('okay')
except Exception as exc:
    assert exc.__class__ is subprocess.TimeoutExpired, exc.__class__

Expected: "okay" printed.
Actual:

Traceback (most recent call last):
  File "../_timeout.py", line 8, in <module>
    subprocess.check_call('sleep 10', shell=True, timeout=1)
  File "/usr/lib64/python3.8/subprocess.py", line 359, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python3.8/subprocess.py", line 342, in call
    return p.wait(timeout=timeout)
  File "/home/dtantsur/Projects/oslo.concurrency/.tox/py3/lib/python3.8/site-packages/eventlet/green/subprocess.py", line 90, in wait
    raise TimeoutExpired(self.args, timeout)
subprocess.TimeoutExpired: Command 'sleep 10' timed out after 1 seconds

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "../_timeout.py", line 12, in <module>
    assert exc.__class__ is subprocess.TimeoutExpired, exc.__class__
AssertionError: <class 'subprocess.TimeoutExpired'>

Using

from eventlet.green import subprocess

fixes the problem but assumes modifying the code which is supposed to work after monkey patching.

@dtantsur
Copy link
Contributor Author

dtantsur commented Jul 6, 2020

This issue seems highly dependent the presence of a virtual env (and moon phases). I could not reproduce it with system python and eventlet on my Fedora, but can easily reproduce in a fresh venv.

I do wonder if we should avoid overriding TimeoutExpired for Python's that have it.

@dtantsur dtantsur changed the title Monkey patching breaks usage of subprocess.TimeoutExpired Monkey patching breaks usage of subprocess.TimeoutExpired in a virtual env Jul 6, 2020
@temoto
Copy link
Member

temoto commented Oct 20, 2020

Maybe related to this branch https://github.com/eventlet/eventlet/commits/subprocess-413-more 18c889e though it doesn't apply to TimeoutExpired and maybe should.

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

No branches or pull requests

2 participants