def from_command(cls, command, before_exec_func=None):
"""
Create Process from command,
e.g. command=['python', '-c', 'print("test")']
:param before_exec_func: Function that is called before `exec` in the
process fork.
"""
assert isinstance(command, list)
assert before_exec_func is None or callable(before_exec_func)
def execv():
if before_exec_func:
before_exec_func()
for p in os.environ['PATH'].split(':'):
path = os.path.join(p, command[0])
if os.path.exists(path) and os.access(path, os.X_OK):
os.execv(path, command)
return cls(execv)
评论列表
文章目录