python 2.7记录日志的问题IOError: [Errno 24] Too many open files
伊谢尔伦
伊谢尔伦 2017-04-18 10:07:15
0
4
1203
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(4)
PHPzhong
fh =logging.FileHandler(BASE_DIR+'/log/'+username+'_'+GetNowTime()+'_'+str(random.random())+'.log')

这个你每一次创建的handler对象有没有调用`fh.close()`来清除此hander的所拥有的资源。
大家讲道理

Too many files are opened. Generally speaking, the default is a maximum of 1024 files.
You need to increase this value to verify how many files you can execute ulimit -a. Look at the "open files" inside.
For more information, please refer to: http:// askubuntu.com/question…

阿神

logger = logging.getLogger('mylogger'+str(time.time()))
There is a problem with this sentence. If you don't run get_task2 once, you will get a file handle. If you run it too many times, it will of course be exceeded!

洪涛
logger = logging.getLogger('mylogger'+str(time.time()))

This way of writing is inherently bad and the potential risks are too high. It is unreasonable to generate a separate log for each request. The Linux system itself also has a limit on the number of files in a directory. If there are too many requests, the upper limit will be reached and an error will occur.

As for whether the handler is closed or not, it can only be said to be a programming error at best, but having a separate log for each request is completely a wrong way of thinking.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template