问题描述
尝试执行使用多处理程序包的python程序时出现错误:
I'm getting an error when trying to execute python program that uses multiprocessing package:
File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line 178, in RLock
return RLock()
File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line 142, in __init__
SemLock.__init__(self, RECURSIVE_MUTEX, 1, 1)
File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line 49, in __init__
sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
OSError: [Errno 13] Permission denied
用户似乎没有访问共享内存的权限.使用root特权执行时,效果很好.
It looks like the user doesn't have permission to access shared memory. When executing with root privileges it works fine.
有什么解决方案可以以普通用户(不是root)身份运行它?
Is there any solution to run it as normal user(not root)?
Python版本2.6.2,操作系统是Linux 2.6.18(CentOS版本5.4),它是VPS计算机.
Python version 2.6.2 , OS is Linux 2.6.18 (CentOS release 5.4) and it's VPS machine.
推荐答案
为使POSIX信号正常工作,用户需要对共享内存(/dev/shm
)进行读/写访问.
For POSIX semaphores to work, the users need r/w access to shared memory (/dev/shm
).
检查对/dev/shm
的权限.在我的笔记本电脑(Ubuntu)上,看起来像这样:
Check the permissions to /dev/shm
. On my laptop (Ubuntu) it looks like this:
$ ls -ld /dev/shm
drwxrwxrwt 2 root root 40 2010-01-05 20:34 shm
要永久设置正确的权限(即使在重新启动后),请在/etc/fstab
中添加以下内容:
To permanently set the correct permissions (even after a reboot), add the following to your /etc/fstab
:
none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0
还没有尝试过,只是从论坛帖子.
Haven't tried this, just copied from a forum post.
这篇关于Python多处理:权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!