Jython:subprocess.Popen用完了文件描述符 [英] Jython: subprocess.Popen runs out of file descriptors
问题描述
我使用Python的Jython 2.51实现来编写一个脚本,它通过 Python子流程文档除了 编辑:以防万一,这是一个多线程的程序,所以有几个 在UNIX上,这是使用fork的副作用,它重复了当前进程以及加载新的可执行文件之前的所有句柄。在Windows上,它是更明确的,但Python无论如何,尝试尽可能匹配跨平台的行为。 close_fds选项,当True,关闭所有这些在产生子进程之后继承了句柄,所以新的可执行文件以干净的版本开始。但是,如果你的子进程一次只运行一次,并在完成时终止,那么这应该不是问题。 I'm using the Jython 2.51 implementation of Python to write a script that repeatedly invokes another process via The Python subprocess documentation mentions very little about freeing file descriptors, other than the Edit: Just in case it makes a difference, this is a multithreaded program, so there are several This only answers part of your question, but my understanding is that, when you spawn a new process, it normally inherits all the handles of the parent process. That includes such things as open files and sockets that you're listening on. On UNIX, that's a side-effect of using 'fork', which duplicates the current process and all of its handles before loading the new executable. On Windows it's more explicit, but Python does it anyway, to try to match the behavior across platforms as much as possible. The close_fds option, when True, closes all these inherited handles after spawning the subprocess, so the new executable starts with a clean slate. But if your subprocesses are run one at a time, and terminating when they're done, then this shouldn't be the problem. 这篇关于Jython:subprocess.Popen用完了文件描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! subprocess.Popen
反复调用另一个进程,并使用 PIPE
到pipe
stdout
和 stderr
到父进程, stdin
到子进程。经过几百次循环迭代,我似乎用尽了文件描述符。
close_fds
选项之外,没有提到非常清楚地描述释放文件描述符的细节(为什么除了0,1和2之外还有任何文件描述符打开第一个地方?)。我假设在CPython中,引用计数处理资源释放问题。在Jython中使用 Popen
对象完成所有描述符的释放的正确方法是什么?
Popen
进程同时运行。
subprocess.Popen
and uses PIPE
to pipe stdout
and stderr
to the parent process and stdin
to the child process. After several hundred loop iterations, I seem to run out of file descriptors. close_fds
option, which isn't described very clearly (Why should there be any file descriptors besides 0, 1 and 2 open in the first place?). I'm assuming that in CPython, reference counting takes care of the resource freeing issue. What's the proper way to make sure all descriptors get freed when one is done with a Popen
object in Jython?Popen
processes running simultaneously.