bash - subprocess popen Python -
i executing shell script starting process background option &. shell script called python script hangs.
shell script:
test -f filename -d & python file
cmd =["shellscript","restart"] proc = subprocess.popen(cmd, stdout=subprocess.pipe, stderr=subprocess.pipe, stdin=subprocess.pipe, **kwargs) pid = proc.pid out, err = proc.communicate() returncode = proc.poll() python file hangs , won't return out of python process. python process automated one.
the call proc.communicate() block until pipes used stderr , stdout closed. if shell script spawns child process inherits pipes, exit after process has closed writing ends of pipes or exited.
to solve can either
- redirect output of started subprocess
/dev/nullor logfile in shell script, e.g.:
subprocess_to_start >/dev/null 2>&1 & - use
subprocess.devnullor open file objectstderr,stdoutin python script , dropcommunicate()call if don't need output of "shellscript" in python
Comments
Post a Comment