拇指快播,对联的起源,购置税减半
目录
代码示例支持 |
---|
平台: centos 6.3 |
python: 2.7.14 |
代码示例: 菜单 - python踩坑指南代码示例 |
长期运行的daemon进程或者socket测试类进程, 经常遇到的坑是:
ioerror: [errno 24] too many open files
即进程遇到 io 错误, 无法打开更多的文件.
一般从两个方面入手:
a. 谁打开谁关闭是个普适的原则:
# with 语法会在生命周期后自动关闭打开的文件 fd with open('xxxx_path.file', 'w') as fhandle: fhandle.dosth()
b. 检查文件 fd 是否存在泄漏
系统设计阶段一般会预估系统总体可打开的 fd 情况. 当出现如下情况时可能出现了泄漏 bug
python 基础库 cup 提供对进程打开 fd 的支持, 详见示例代码.
以 centos 6.3 linux系统
为例, 查看 /etc/security/limits.conf 获得系统软硬限资源
* soft nofile 10240 * hard nofile 10240
其中, 用户不能突破系统的硬线 hard nofile limit
.
用户也可以通过 shell 命令 ulimit -n 来限定该 shell 启动的所有进程的 nofile
ulimit -a
可以查看当前用户被设定的限制, 示例:
[test@agent1 ~]$ ulimit -a core file size (blocks, -c) 0 ....... open files (-n) 10240 ..... virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
life is short. we use python.
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新手学习Python2和Python3中print不同的用法
Python基于os.environ从windows获取环境变量
网友评论