此事件已被另一个greenlet使用

时间:2014-04-01 06:56:30

标签: python mysql gunicorn greenlets

我使用带有worker_class="gevent", workers=3的gunicorn 17.5,我以gunicorn -c config.py my:app开头。我刚注意到我的日志中出现以下错误

2014-04-01 04:48:49 [4297] [ERROR] Error handling request
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/gunicorn/workers/async.py", line 45, in handle
    self.handle_request(listener, req, client, addr)
  File "/usr/lib/python2.6/site-packages/gunicorn/workers/ggevent.py", line 119, in handle_request
    super(GeventWorker, self).handle_request(*args)
  File "/usr/lib/python2.6/site-packages/gunicorn/workers/async.py", line 93, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/usr/lib/python2.6/site-packages/beaker/middleware.py", line 155, in __call__
    return self.wrap_app(environ, session_start_response)
  [...]
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 1083, in cursor
    if not self.is_connected():
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 696, in is_connected
    self.cmd_ping()
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 665, in cmd_ping
    return self._handle_ok(self._send_cmd(ServerCmd.PING))
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 378, in _send_cmd
    return self._socket.recv()
  File "/usr/lib/python2.6/site-packages/mysql/connector/network.py", line 170, in recv_plain
    packet = self.sock.recv(1)
  File "/usr/lib64/python2.6/site-packages/gevent/socket.py", line 432, in recv
    wait_read(sock.fileno(), timeout=self.timeout, event=self._read_event)
  File "/usr/lib64/python2.6/site-packages/gevent/socket.py", line 165, in wait_read
    assert event.arg is None, 'This event is already used by another greenlet: %r' % (event.arg, )
AssertionError: This event is already used by another greenlet: (<Greenlet at 0x37ac190: <functools.partial object at 0x2578788>(<socket at 0x37ab9d0 fileno=14 sock=10.174.17.169:, ('173.228.6.207', 18614))>, timeout('timed out',))

一点点搜索似乎表明我可能正在使用一些在导入之前没有修补猴子的模块或者不兼容greenlet。然而,mysql连接器是纯python,因此似乎暗示它是兼容的。 worker_class=gevent似乎在初始化时调用monkey.patch_all()。可以肯定的是,我在应用的第一行添加了import gevent.monkey; gevent.monkey.patch_all(),但它没有任何帮助。我注意到的最后一件事是:当我按下我的应用程序时,我得到了这个

Exception KeyError: KeyError(36957072,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored

我在网上看到这表明在导入线程后完成了猴子补丁。根据我提到的背景,知道如何发生这种情况吗?

如果可以提供帮助:我的应用程序在启动时会打开一堆mysql连接,但我不保证它们将被独占使用 - 即我没有连接池具有获取/释放语义,它们只是由传入的客户端请求随机使用。有某种连接池会有帮助吗?如果是,如何确保这与gevent / greenlets很好地协同工作?

0 个答案:

没有答案