Skip to content

Limitation because subprocess.run with timeout doesnt work for child processes #51

Description

@bigbitbus

I am trying to use a timeout to kill a subprocess launched via .run(timeout=); this is not supported unlike the original subprocess.run()

To reproduce:

Python 3.8.12 (default, Oct 27 2021, 12:52:48) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess_tee import run
>>> run('sleep 10', shell=True, timeout=.1, capture_output=True)
CompletedProcess(args='sleep 10', returncode=0, stdout='', stderr='')

Whereas with subprocess.run the exception is correctly thrown:

Python 3.8.12 (default, Oct 27 2021, 12:52:48) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from subprocess import run
>>> run('sleep 10', shell=True, timeout=.1, capture_output=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/subprocess.py", line 495, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/usr/local/lib/python3.8/subprocess.py", line 1028, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/usr/local/lib/python3.8/subprocess.py", line 1869, in _communicate
    self._check_timeout(endtime, orig_timeout, stdout, stderr)
  File "/usr/local/lib/python3.8/subprocess.py", line 1072, in _check_timeout
    raise TimeoutExpired(
subprocess.TimeoutExpired: Command 'sleep 10' timed out after 0.1 seconds

The output should have been a TimedoutException.

Also tried

>>> run(['sleep','10'], shell=False, timeout=.1, capture_output=False)
CompletedProcess(args=['sleep', '10'], returncode=0, stdout='', stderr='')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions