2012-12-20 78 views
1

问题有类似的问题: Parallel Python - too many filesPython too many open files (subprocesses)打开的文件太多并行的Python子进程错误

我使用Python的并行[V1.6.2]运行的任务。该任务处理输入文件并输出日志/报告。假设有10个文件夹,每个文件夹有5000〜20000个并行读取,处理和日志写出的文件。每个文件约为50KB〜250KB

运行约6小时后,并行Python失败,并显示以下错误。

File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 342, in __init__ 
    File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 506, in set_ncpus 
    File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 140, in __init__ 
    File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 146, in start 
    File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ 
    File "/usr/lib/python2.7/subprocess.py", line 1135, in _execute_child 
    File "/usr/lib/python2.7/subprocess.py", line 1091, in pipe_cloexec 
OSError: [Errno 24] Too many open files 
Error in sys.excepthook: 
Traceback (most recent call last): 
    File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in apport_excepthook 
ImportError: No module named fileutils 

Original exception was: 
Traceback (most recent call last): 
    File "PARALLEL_TEST.py", line 746, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 342, in __init__ 
    File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 506, in set_ncpus 
    File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 140, in __init__ 
    File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 146, in start 
    File "/usr/lib/python2.7/subprocess.py", line 679, in __init__ 
    File "/usr/lib/python2.7/subprocess.py", line 1135, in _execute_child 
    File "/usr/lib/python2.7/subprocess.py", line 1091, in pipe_cloexec 
OSError: [Errno 24] Too many open files 

虽然我明白,这可能是在子这里的问题http://bugs.python.org/issue2320指出,但是,似乎解决办法只有PY V3.2的一部分。我目前绑定到Py V2.7。

我想知道如果下面的建议可以帮助: [1] http://www.parallelpython.com/component/option,com_smf/Itemid,1/topic,313.0

*)添加worker.t.close()中的destroy()/usr/local/lib/python2.7的方法/dist-packages/pp-1.6.2-py2.7.egg/pp.py

*)在/usr/local/lib/python2.7/dist-packages/pp-1.6.2-增加BROADCAST_INTERVAL, py2.7.egg/ppauto.py

我想知道在Python V2.7中是否有修复程序可用/解决此问题。

在此先感谢

+0

我已经离开了一些线路来销毁作业服务器。 job_server.destroy()修复了这个问题。 – user1652054

回答

0

我已经离开了一些行来销毁作业服务器。 job_server.destroy()修复了这个问题。

1

我的团队最近偶然发现了一个类似的问题,即在运行芹菜任务队列作业时出现相同的文件句柄资源耗尽问题。我相信OP已经明白了它,它很可能是Python 2.7和Python 3.1中suprocess.py lib中的混乱代码。

Python Bug#2320所示,请在您拨打subprocess.Popen()的任何地方通过close_fds=True。事实上,他们在Python 3.2中将其设为默认值,同时也解决了基础竞争条件问题。在该门票中查看更多详情。