Mac OSX上的龙卷风+ kevent

时间:2014-12-05 00:57:37

标签: python macos tornado kevent

我最近遇到了在Mac OSX Yosemite上运行龙卷风的问题。在向龙卷风服务器发出请求时,我得到以下回溯:

ERROR:tornado.general:Uncaught exception
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/tornado/http1connection.py", line 674, in _server_request_loop
    ret = yield conn.read_response(request_delegate)
  File "/Library/Python/2.7/site-packages/tornado/gen.py", line 628, in run
    value = future.result()
  File "/Library/Python/2.7/site-packages/tornado/concurrent.py", line 109, in result
    raise_exc_info(self._exc_info)
  File "/Library/Python/2.7/site-packages/tornado/gen.py", line 175, in wrapper
    yielded = next(result)
  File "/Library/Python/2.7/site-packages/tornado/http1connection.py", line 157, in _read_message
    max_bytes=self.params.max_header_size)
  File "/Library/Python/2.7/site-packages/tornado/iostream.py", line 227, in read_until_regex
    self._try_inline_read()
  File "/Library/Python/2.7/site-packages/tornado/iostream.py", line 673, in _try_inline_read
    self._add_io_state(ioloop.IOLoop.READ)
  File "/Library/Python/2.7/site-packages/tornado/iostream.py", line 881, in _add_io_state
    self.fileno(), self._handle_events, self._state)
  File "/Library/Python/2.7/site-packages/tornado/ioloop.py", line 677, in add_handler
    self._impl.register(fd, events | self.ERROR)
  File "/Library/Python/2.7/site-packages/tornado/platform/kqueue.py", line 41, in register
    self._control(fd, events, select.KQ_EV_ADD)
  File "/Library/Python/2.7/site-packages/tornado/platform/kqueue.py", line 59, in _control
    kevents.append(select.kevent(
AttributeError: 'module' object has no attribute 'kevent'

最后一行是最重要的。我相当肯定这只是因为缺少brew包,但我不知道我能错过什么。

更神秘的是,我可以导入select并查看kevent函数是否存在。

Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import select
>>> select.kevent
<type 'select.kevent'>

1 个答案:

答案 0 :(得分:0)

所以我提出了一个临时的解决方案,即使是在回答这个问题我也感到有点内疚,但无论如何它在这里:

1)打开/usr/local/lib/python2.7/site-packages/tornado/platform/kqueue.py(或类似的)。 2)在import select之后,立即添加以下行:

cached_kevent = select.kevent

3)替换以下行:

kevents.append(select.kevent(
    fd, filter=select.KQ_FILTER_READ, flags=flags))

使用此修改版本:

try:
    kevents.append(select.kevent(
        fd, filter=select.KQ_FILTER_READ, flags=flags))
except AttributeError:
    kevents.append(cached_kevent(
       fd, filter=select.KQ_FILTER_READ, flags=flags))

非常感谢任何更好的答案。