2023-05-18 18:20:50 +02:00
|
|
|
# Module inspired by subprocess which allows for asynchronous
|
|
|
|
# multiprocessing
|
2023-06-06 11:31:30 +02:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
from subprocess import (
|
|
|
|
CalledProcessError,
|
|
|
|
CompletedProcess,
|
|
|
|
SubprocessError,
|
|
|
|
STDOUT,
|
|
|
|
DEVNULL,
|
|
|
|
PIPE
|
|
|
|
)
|
2023-05-18 18:20:50 +02:00
|
|
|
|
|
|
|
|
2023-06-06 11:31:30 +02:00
|
|
|
class Popen:
|
2023-05-18 18:20:50 +02:00
|
|
|
"""
|
2023-06-06 11:31:30 +02:00
|
|
|
Wrapper around subprocess.Popen, but async
|
2023-05-18 18:20:50 +02:00
|
|
|
"""
|
|
|
|
|
2023-06-06 11:31:30 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Public object constructor
|
|
|
|
"""
|
|
|
|
|
|
|
|
if "universal_newlines" in kwargs:
|
|
|
|
# Not sure why? But everyone else is doing it so :shrug:
|
|
|
|
raise RuntimeError("universal_newlines is not supported")
|
|
|
|
if stdin := kwargs.get("stdin"):
|
|
|
|
# Curio mentions stuff breaking if the child process
|
|
|
|
# is passed a stdin fd that is set to non-blocking mode
|
|
|
|
if hasattr(os, "set_blocking"):
|
|
|
|
os.set_blocking(stdin.fileno(), True)
|
|
|
|
# Delegate to Popen's constructor
|
|
|
|
self._process = subprocess.Popen(*args, **kwargs)
|
|
|
|
|
|
|
|
def __getattr__(self, item):
|
|
|
|
# Delegate to internal process object
|
|
|
|
return getattr(self._process, item)
|
|
|
|
|