Python.popen hanging subprocess

            child = subprocess.Popen(command,
                         shell=True,
                         env=environment,
                         close_fds=True,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT,
                         bufsize=1,
                                     )

            subout = ""
            with child.stdout:
                for line in iter(child.stdout.readline, b''):
                    subout += line
            logging.info(subout)
            rc = child.wait()

several times (intermittently) it is forever. not sure if it hangs on iter(child.stdout.readline)orchild.wait()

i ps -effor the process that it pops up and that process no longer exists

I assume it deals with bufsize, so child.stdout.readline goes on forever, but I have no idea how to test it, and since it happens intermittently

I could implement an alarm, but I'm not sure if this is suitable, because I can’t really tell if the popen'd process is just slow or hanging

Let's say either child.stdout.readline or wait () hangs forever, what actions could I take besides the alarm?

+4
source share
1

, , :

Popen.wait():

. returncode.

: stdout=PIPE / stderr=PIPE, , OS, , communicate(), .

Popen.communicate().

+6

Source: https://habr.com/ru/post/1654496/


All Articles