OSError:[Erno 24]python导入上打开的文件太多



我有一个测试环境,它使用从c代码调用python

system("flows_parser.py ....");

运行了很长一段时间后,我每次都会出现以下错误:

Traceback (most recent call last):
File "/homes/fw/antvai01/work/cc312r2/cc_validation/hta/flows_parser/flows_parser.py", line 32, in <module>
File "/homes/fw/antvai01/work/cc312r2/cc_validation/hta/flows_parser/../../shared/proto_steps/common/generated_py/proto_steps_common_steps_defines_pb2.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 661, in exec_module
File "<frozen importlib._bootstrap_external>", line 766, in get_code
File "<frozen importlib._bootstrap_external>", line 818, in get_data
OSError: [Errno 24] Too many open files: '/usr/local/lib/python3.5/dist-packages/google/protobuf/reflection.py'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 661, in exec_module
File "<frozen importlib._bootstrap_external>", line 766, in get_code
File "<frozen importlib._bootstrap_external>", line 818, in get_data
OSError: [Errno 24] Too many open files: '/usr/lib/python3/dist-packages/apport/__init__.py'
Original exception was:
Traceback (most recent call last):
File "/homes/fw/antvai01/work/cc312r2/cc_validation/hta/flows_parser/flows_parser.py", line 32, in <module>
File "/homes/fw/antvai01/work/cc312r2/cc_validation/hta/flows_parser/../../shared/proto_steps/common/generated_py/proto_steps_common_steps_defines_pb2.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 661, in exec_module
File "<frozen importlib._bootstrap_external>", line 766, in get_code
File "<frozen importlib._bootstrap_external>", line 818, in get_data
OSError: [Errno 24] Too many open files: '/usr/local/lib/python3.5/dist-packages/google/protobuf/reflection.py'

proto_steps_common_steps_define_pb2导入中的flows_parser.py行32proto_steps_common_steps_define_pb2.py行9也是反射的导入。

我在Ubuntu 16.4上输出:sysctl-A|grep-shm-

kernel.shm_next_id = -1
kernel.shm_rmid_forced = 0
kernel.shmall = 18446744073692774399
kernel.shmmax = 18446744073692774399
kernel.shmmni = 4096
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.enp0s3.stable_secret"
sysctl: reading key "net.ipv6.conf.enp0s8.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
vm.hugetlb_shm_group = 0

所以shmmax不应该成为问题。有人能帮忙吗?

感谢Ricardo Branco!它是c代码中的描述符leek,与python无关。我制作了管道,完成后没有把它们关上。我找到了描述符leek并将其插入,现在工作正常。

最新更新