twisted.internet.reactor.spawnProcess 引发 OSError(13, '权限被拒绝')

3 投票
1 回答
1197 浏览
提问于 2025-04-16 22:58

当我尝试通过 `twisted.internet.reactor.spawnProcess` 来运行一个 Python 脚本时:

from twisted.internet import protocol, reactor

class ProcessProtocol(protocol.ProcessProtocol):
    def connectionMade(self):
        self.transport.closeStdin()

    def childDataReceived(self, childFD, data):
        print data

def main():
    proto = ProcessProtocol()
    cmd = ['/var/projects/python/worker.py']
    reactor.spawnProcess(proto, cmd[0], cmd)

if __name__ == "__main__":
    exit(main())

我遇到了以下错误:

Upon execvpe /var/projects/python/worker.py ['/var/projects/python/worker.py', '5'] in environment id 29011152
:Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Twisted-11.0.0-py2.6-linux-x86_64.egg/twisted/internet/process.py", line 414, in _fork
    executable, args, environment)
  File "/usr/local/lib/python2.6/dist-packages/Twisted-11.0.0-py2.6-linux-x86_64.egg/twisted/internet/process.py", line 460, in _execChild
    os.execvpe(executable, args, environment)
  File "/usr/lib/python2.6/os.py", line 353, in execvpe
    _execvpe(file, args, env)
  File "/usr/lib/python2.6/os.py", line 368, in _execvpe
    func(file, *argrest)
OSError: [Errno 13] Permission denied

1 个回答

4

你可能没有权限去执行 '/var/projects/python/worker.py' 这个文件,或者这个脚本的执行权限没有设置好。你可以用 ls -l /var/projects/python/worker.py 这个命令来查看一下。

撰写回答