On this page
subprocess.TimeoutExpired
Prev: subprocess.SubprocessError | Up: subprocess
Rel: subprocess.call, subprocess.CalledProcessError, subprocess.check_call, subprocess.check_output
Ref: docs.python.org — subprocess.TimeoutExpired
Tags: #public #python3 #stdlib #subprocess
Import
import subprocess
from subprocess import TimeoutExpired
Signature & Overview
subprocess.TimeoutExpired(cmd, timeout, output=None, stderr=None)
This exception is raised when the timeout expires while waiting for a child process.
Methods & Attributes
TimeoutExpired.add_note(self, note, /)— Add a note to the exceptionTimeoutExpired.stdout(...)—TimeoutExpired.stdoutmethod/property.TimeoutExpired.with_traceback(self, tb, /)— Set self.traceback to tb and return self.
Usage
import subprocess
import sys
try:
subprocess.run([sys.executable, "-c", "import time; time.sleep(5)"], timeout=0.05)
except subprocess.TimeoutExpired as exc:
assert exc.timeout > 0 and exc.cmd[0] == sys.executable
Gotchas
subprocess.run()kills and reaps the child automatically on timeout: With rawPopen.communicate(timeout=...), you must manually callproc.kill()andproc.communicate()in theexceptblock.- Partial output is preserved: Inspect
exc.stdoutandexc.stderr(note: they may bebyteseven whentext=Truein some Python versions).
REPL Inspect
from subprocess import TimeoutExpired
help(TimeoutExpired)
Linked from
Related notes
- tuts/python3/stdlib_module/subprocess/SubprocessError Linked here; links to this page; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/subprocess/call Linked here; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/CalledProcessError Linked here; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/check_call Linked here; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/check_output Linked here; shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/CompletedProcess shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/getoutput shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/getstatusoutput shared tags: #stdlib, #subprocess
- tuts/python3/stdlib_module/subprocess/Popen shared tags: #stdlib, #subprocess