简体   繁体   English

OSError:[Errno 24]从终端调用脚本时打开的文件太多

[英]OSError: [Errno 24] Too many open files when invoking script from terminal

Ubuntu 14.04, Pycharm 5.0.1, Python 3.4.3 Ubuntu 14.04,Pycharm 5.0.1,Python 3.4.3

I have a multi thread intensive script (over 1k) which uses lots of files and sockets it also produces lots of logs. 我有一个多线程密集型脚本(超过1k),该脚本使用大量文件和套接字,它还会生成大量日志。 The problem I am facing is very peculiar. 我面临的问题非常特殊。 Starting the script from pycharm works fine, however invoking the script from terminal produces after a while 从pycharm启动脚本工作正常,但是过一会儿从终端调用脚本会产生

OSError: [Errno 24] Too many open files. 

the limits showed by 显示的极限

  ulimit -Hn 

are over 100k, and once again starting from pycharm works fine, starting: 超过10万,并且再次从pycharm开始工作正常,开始于:

 python3 my_script.py

Produces the error, I even tried using sudo, no luck. 产生错误,我什至尝试使用sudo,没有运气。 Can anybody explain what is happening? 有人可以解释发生了什么吗?

EDIT 编辑

Done some more testing and from the looks of if, it seems that starting the script by pycharm it starts as true multhireaded process and starting from bash does not. 做了一些测试,从外观上看,似乎是通过pycharm启动脚本的,它是作为真正的多进程读取的,而不是从bash开始的。 I base this on results of ps aux: 我基于ps aux的结果:

USER PID  %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user1   * * * * *            ? Sl   17:38  73:30 /usr/bin/python3.4 /home/user1/new_main.py
user1   * * * * *            ? S+   17:40  71:30 python3.4 /home/user1/new_main.py

For those like me who need a small reference, here is an extract 对于像我这样需要少量参考的人,这里是摘录

STAT = multi-character process state
PROCESS STATE CODES
   Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process:
   S    interruptible sleep (waiting for an event to complete)

   For BSD formats and when the stat keyword is used, additional characters may be displayed:
   l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
   +    is in the foreground process group.

So the system says that the script started by pycharm (Sl) is multithreaded and the other is not. 因此系统说由pycharm(Sl)启动的脚本是多线程的,而另一个则不是。

I believe when you run your script using PyCharm, the IDE adds some options to the command line. 我相信,当您使用PyCharm运行脚本时,IDE会在命令行中添加一些选项。

To find the command used by pycharm : 查找pycharm使用的命令:

  • run your program using pycharm. 使用pycharm运行程序。
  • then (while your program runs) type in a terminal : ps aux | grep my_script.py 然后(在程序运行时)输入终端: ps aux | grep my_script.py ps aux | grep my_script.py

I had the same issue playing with multi threads and other file descriptors, a way to avoid the problem would probably be by optimizing your code, and / or reducing the maximal number of threads. 使用多线程和其他文件描述符时,我遇到了相同的问题,一种避免问题的方法可能是优化代码和/或减少最大线程数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSError:[Errno 24]打开的文件太多 - OSError: [Errno 24] Too many open files OSError: [Errno 24] 打开的文件太多 - OS Mojave - OSError: [Errno 24] Too many open files - OS Mojave OSError:[Errno 24]太多打开的文件python,ubuntu - OSError: [Errno 24] Too many open files python , ubuntu OSError: [Errno 24] 使用 Nibabel 打开的文件太多 - OSError: [Errno 24] Too many open files using Nibabel slackclient OSError:[Errno 24]打开的文件太多 - slackclient OSError: [Errno 24] Too many open files OSError:[Errno 24]在Twisted中使用Reactor.run()时打开的文件过多 - OSError: [Errno 24] Too many open files when using reactor.run() in Twisted OSError: [Errno 24] 在 tensorflow-federated 中训练差分隐私时打开的文件过多 - OSError: [Errno 24] Too many open files when training differential privacy in tensorflow-federated Django从一个图像域保存到另一个图像域:OSError:[Errno 24]打开的文件太多 - Django saving from one imagefield to another: OSError: [Errno 24] Too many open files “ OSError:[Errno 24]打开的文件太多:”和来自aiocoap context.request()的套接字 - “OSError: [Errno 24] Too many open files:” with sockets from aiocoap context.request() 为什么在使用mrjob v0.4.4时,[Errno 7]参数列表过长且OSError:[Errno 24]打开的文件太多? - Why am I getting [Errno 7] Argument list too long and OSError: [Errno 24] Too many open files when using mrjob v0.4.4?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM