Program often die, positioning for a half-day only to locate the reason, the original is popen caused by the card dead;
The procedure is as follows:
s = subprocess. Popen ([*,*,*], stdout=subprocess. PIPE)
ret = S.stdout.read ()
return ret
The official documentation is interpreted as:
This would deadlock when using and/or and the child stdout=PIPE
stderr=PIPE
process generates enough output to a pipe such that it bloc KS waiting for the OS pipe buffer to accept more data. Use to communicate()
avoid.
The reason is that Popen.
wait
after using () direct read PIPE.stdout.read (), the cache may be full, causing the card to die at this time.
Workaround: Use Communicate ()
For example:
s = subprocess. Popen ([*,*,*], stdout=subprocess. PIPE)
Stdoutdata, Stderrdata = S.communicate ()
Return Stdoutdata
In addition, finally, when calling Popen, add the parameter close_fds=true, see the official documentation Note:
Popen2 closes all file descriptors by default, and you had to specify close_fds=true with Popen
Later use Popen or be careful, this inside pit many.
Python popen stuck to the dead.