gevent的子进程因OSError 22(EINVAL)而失败?

时间:2012-12-05 22:26:44

标签: python gevent

将我的开发笔记本电脑升级到Mountain Lion后,我注意到gevent.subprocess.Popen失败了......有时候。

我有一个功能:

from gevent.subprocess import check_output
def do_stuff():
    result = check_output(["file", "foo.py"], stderr=STDOUT)

下面的追溯失败了:

Traceback (most recent call last):
  ...
  File "myfile.py", line 105, in do_stuff
    result = check_output(["file", "foo.py"], stderr=STDOUT)
  File ".../gevent/subprocess.py", line 154, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File ".../gevent/subprocess.py", line 231, in __init__
    errread, errwrite)
  File ".../gevent/subprocess.py", line 714, in _execute_child
    data = errpipe_read.read(1048576)
  File "...ython2.7/socket.py", line 380, in read
    data = self._sock.recv(left)
  File ".../gevent/fileobject.py", line 114, in recv
    data = os.read(self.fileno(), size)
OSError: [Errno 22] Invalid argument

但是,我尝试重新创建错误:

from gevent import monkey; monkey.patch_all()

import os
import gevent
from gevent.subprocess import check_output, STDOUT

def stuff(x):
    f = x and "/dev/asdf" or "/dev/null"
    print check_output(["file", f], stderr=STDOUT).strip()

while True:
    pid = gevent.fork()
    if pid == 0:
        gevent.joinall([
            gevent.spawn(stuff, x % 2)
            for x in range(10)
        ])
    else:
        os.waitpid(-1, 0)
    gevent.sleep(1)

失败了。上述程序没有问题。

发生了什么事?或者,至少,关于我如何开始调试它的任何指针?

版本:gevent 1.0b3,Python 2.7.2,OS X 10.8.2,libev 4.11(来自自制软件)。

1 个答案:

答案 0 :(得分:0)

调查1.0RC1 change log似乎这是一个已修复的已知问题。升级到1.0RC1确实解决了这个问题。