12 | 12 |
import warnings
|
13 | 13 |
from multiprocessing import Pipe
|
14 | 14 |
from threading import Thread
|
15 | |
from typing import Any, Callable, Optional
|
|
15 |
from typing import Any, Callable, Optional, Union
|
16 | 16 |
|
17 | 17 |
#
|
18 | 18 |
# run() - A function to synchronously run an external process, supporting
|
|
303 | 303 |
command,
|
304 | 304 |
*,
|
305 | 305 |
timeout: Optional[float] = None,
|
306 | |
stdin: Optional[bytes] = None,
|
|
306 |
stdin: Optional[Union[bytes, int]] = None,
|
307 | 307 |
print_stdout: bool = True,
|
308 | 308 |
print_stderr: bool = True,
|
309 | 309 |
callback_stdout: Optional[Callable] = None,
|
|
322 | 322 |
|
323 | 323 |
:param array command: Command line to be run, specified as array.
|
324 | 324 |
:param timeout: Terminate program execution after this many seconds.
|
325 | |
:param stdin: Optional bytestring that is passed to command stdin.
|
|
325 |
:param stdin: Optional bytestring that is passed to command stdin,
|
|
326 |
or subprocess.DEVNULL to disable stdin.
|
326 | 327 |
:param boolean print_stdout: Pass stdout through to sys.stdout.
|
327 | 328 |
:param boolean print_stderr: Pass stderr through to sys.stderr.
|
328 | 329 |
:param callback_stdout: Optional function which is called for each
|
|
347 | 348 |
|
348 | 349 |
if stdin is None:
|
349 | 350 |
stdin_pipe = None
|
|
351 |
elif isinstance(stdin, int):
|
|
352 |
assert (
|
|
353 |
stdin == subprocess.DEVNULL
|
|
354 |
), "stdin argument only allows subprocess.DEVNULL as numeric argument"
|
|
355 |
stdin_pipe = subprocess.DEVNULL
|
|
356 |
stdin = None
|
350 | 357 |
else:
|
351 | 358 |
assert sys.platform != "win32", "stdin argument not supported on Windows"
|
352 | 359 |
stdin_pipe = subprocess.PIPE
|