subprocess.Popen.communicate()不能正常执行

在本身电脑上是好的,可是移植到windows2003的服务器上运行的时候每次就会卡着这行代码这里不能正常执行。python

搜寻资料中发现有以下解释(参考https://bugs.python.org/issue1731717):windows

It appears that subprocess calls a module global "_cleanup()" whenever opening a new subprocess. This method is meant to reap any child processes that have terminated and have not explicitly cleaned up. These are processes you would expect to be cleaned up by GC, however, subprocess keeps a list of of all spawned subprocesses in _active until they are reaped explicitly so it can cleanup any that nolonger referenced anywhere else.

The problem is lots of methods, including poll() and wait(), check self.returncode and then modify it. Any non-atomic read/modify action is inherently non-threadsafe. And _cleanup() calls poll() on all un-reaped child processes. If two threads happen to try and spawn subprocesses at once, these _cleanup() calls collide..

The way to fix this depends on how thread-safe you want to make it. If you want to share popen objects between threads to wait()/poll() with impunity from any thread, you should add a recursive lock attribute to the Popen instance and have it lock/release it at the start/end of every method call.

其余相关资料:服务器

https://bugs.python.org/issue9127app

https://hg.python.org/cpython/rev/767420808a62ide

----------------------12月10日更新分割线---------------------------this

结果:就是程序的问题,或者更明确地说是child子程序的问题。因此说,程序的世界里是没有未解之谜的,一切都是有据可循的,若是出现了奇怪的错误,只须要默默好好的检查本身代码。atom

相关文章
相关标签/搜索