screenshare/venv/lib/python3.12/site-packages/easyprocess/examples/timeout.py
2024-11-29 18:15:30 +00:00

25 lines
472 B
Python

import sys
from easyprocess import EasyProcess
python = sys.executable
prog = """
import time
for i in range(3):
print(i, flush=True)
time.sleep(1)
"""
print("-- no timeout")
stdout = EasyProcess([python, "-c", prog]).call().stdout
print(stdout)
print("-- timeout=1.5s")
stdout = EasyProcess([python, "-c", prog]).call(timeout=1.5).stdout
print(stdout)
print("-- timeout=50s")
stdout = EasyProcess([python, "-c", prog]).call(timeout=50).stdout
print(stdout)