Ubuntu 14.04,Pycharm 5.0.1,Python 3.4.3
我有一个多线程密集型脚本(超过1k),它使用大量文件和套接字,它也会生成大量日志。我面临的问题非常奇怪。从pycharm启动脚本工作正常,但是从终端调用脚本会在一段时间后生成
OSError: [Errno 24] Too many open files.
显示的限制
ulimit -Hn
超过100k,再次从pycharm开始工作正常,开始:
python3 my_script.py
产生错误,我甚至尝试使用sudo,没有运气。谁能解释一下发生了什么?
修改
做了一些更多的测试,从if的外观来看,似乎通过pycharm启动脚本它开始是真正的multhireaded进程并且从bash开始没有。我的基础是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
对于像我这样需要小参考的人,这里有一个摘录
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.
因此系统说pycharm(S1)启动的脚本是多线程的,而另一个则不是。
答案 0 :(得分:0)
我相信当您使用PyCharm运行脚本时,IDE会在命令行中添加一些选项。
查找pycharm使用的命令:
ps aux | grep my_script.py
我在使用多线程和其他文件描述符时遇到了同样的问题,可以通过优化代码和/或减少最大线程数来避免问题。