Python - OSError 24 (Too many open files) and shared memory

ぃ、小莉子 提交于 2019-12-11 03:13:52

问题


I faced with the problem there was exception OSError 24 ("Too many open files") raised on my mac os x in python script.

I had no idea what could caused that issue. lsof -p showed about 40-50 lines, and my ulimit was 1200 (I check that using

resource.getrlimit(resource.RLIMIT_NOFILE)

), that returned tuple (1200, 1200). So I didn't exceed limit even closely.

That my script spawned number of subprocesses and also allocated shared memory segments. Exception occurred while allocating shared memory segments. I use sysv_ipc module.

Also I knew I total allowed number of shared memory segments is enough large (128 segments), and command

ipcs -b -m

gave definitely less number (not more then 40 segments).


回答1:


The issue was in shared memory system settings (shared memory – wiki).

There is parameter kern.sysv.shmseg in /etc/sysctl.conf file which represents the maximum number of shared memory segments each process can attach. So I had value 32 that was not enough for my script.

To view parameters, use:

sysctl -A | grep shm

To update that parameters, edit file:

sudo vim /etc/sysctl.conf

My looks now like that:

kern.sysv.shmmax=564777216
kern.sysv.shmmin=1
kern.sysv.shmmni=700
kern.sysv.shmseg=128
kern.sysv.shmall=131072

Notice, you need restart system in order to apply settings.

To view currently allocated shared memory segments, type:

ipcs -m -b

To remove all shared memory segments:

for n in `ipcs -b -m | egrep ^m | awk '{ print $2; }'`; do ipcrm -m $n; done

Notice, only segments that are not attached to any process will be really removed.

More on shared memory settings: http://techjournal.318.com/general-technology/shared-memory-settings-explain/, http://www.spy-hill.com/help/apple/SharedMemory.html, http://support.apple.com/kb/HT4022



来源:https://stackoverflow.com/questions/13641169/python-oserror-24-too-many-open-files-and-shared-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!