1
0
Fork 0

fix python file execution checking

This commit is contained in:
Nick Sweeting 2021-04-24 04:43:02 -04:00
parent 3d40693f1c
commit c3d009e4ec

View file

@ -18,7 +18,7 @@ from .config import PYTHON_BINARY, OUTPUT_PERMISSIONS
def run(*args, input=None, capture_output=True, timeout=None, check=False, text=False, start_new_session=True, **kwargs):
def run(cmd, *args, input=None, capture_output=True, timeout=None, check=False, text=False, start_new_session=True, **kwargs):
"""Patched of subprocess.run to kill forked child subprocesses and fix blocking io making timeout=innefective
Mostly copied from https://github.com/python/cpython/blob/master/Lib/subprocess.py
"""
@ -37,10 +37,10 @@ def run(*args, input=None, capture_output=True, timeout=None, check=False, text=
pgid = None
try:
if args[0].endswith('.py'):
args = (PYTHON_BINARY, *args)
if isinstance(cmd, (list, tuple)) and cmd[0].endswith('.py'):
cmd = (PYTHON_BINARY, *cmd)
with Popen(*args, start_new_session=start_new_session, **kwargs) as process:
with Popen(cmd, *args, start_new_session=start_new_session, **kwargs) as process:
pgid = os.getpgid(process.pid)
try:
stdout, stderr = process.communicate(input, timeout=timeout)