2 from eventlet.green import subprocess
3 import eventlet.patcher
6 original_subprocess = eventlet.patcher.original('subprocess')
9 def test_subprocess_wait():
10 # https://bitbucket.org/eventlet/eventlet/issue/89
11 # In Python 3.3 subprocess.Popen.wait() method acquired `timeout`
13 # RHEL backported it to their Python 2.6 package.
14 cmd = [sys.executable, "-c", "import time; time.sleep(0.5)"]
15 p = subprocess.Popen(cmd)
20 except subprocess.TimeoutExpired as e:
21 str(e) # make sure it doesn't throw
23 assert e.timeout == 0.1
25 tdiff = time.time() - t1
26 assert ok, 'did not raise subprocess.TimeoutExpired'
27 assert 0.1 <= tdiff <= 0.2, 'did not stop within allowed time'
30 def test_communicate_with_poll():
31 # This test was being skipped since git 25812fca8, I don't there's
32 # a need to do this. The original comment:
34 # https://github.com/eventlet/eventlet/pull/24
35 # `eventlet.green.subprocess.Popen.communicate()` was broken
36 # in Python 2.7 because the usage of the `select` module was moved from
37 # `_communicate` into two other methods `_communicate_with_select`
38 # and `_communicate_with_poll`. Link to 2.7's implementation:
39 # http://hg.python.org/cpython/file/2145593d108d/Lib/subprocess.py#l1255
42 [sys.executable, '-c', 'import time; time.sleep(0.5)'],
43 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
45 eventlet.with_timeout(0.1, p.communicate, timeout_value=True)
46 tdiff = time.time() - t1
47 assert 0.1 <= tdiff <= 0.2, 'did not stop within allowed time'
50 def test_close_popen_stdin_with_close_fds():
53 stdin=subprocess.PIPE,
54 stdout=subprocess.PIPE,
55 stderr=subprocess.PIPE,
65 except Exception as e:
66 assert False, "Exception should not be raised, got %r instead" % e