"This event is already used by another greenlet"

372 views
Skip to first unread message

Alec Thomas

unread,
Jun 20, 2010, 7:47:27 AM6/20/10
to gev...@googlegroups.com
Hello,

I have a frontend WSGI server that connects to backend servers using
Thrift. If I use monkey.patch_socket() I get assertion errors whenever
the frontend performs a Thrift RPC call:

AssertionError: This event is already used by another greenlet:
(<Greenlet at 0x18524f8: <bound method SilentWSGIServer.handle of
<SilentWSGIServer at 0x537e10 fileno=6
address=0.0.0.0:57005>>(<http_request _obj=0x164bc10 "GET
/series?keys=22)>, timeout('timed out',))

(SilentWSGIServer is a subclass of gevent.wsgi.WSGIServer, but both
have the same issue)

If I don't monkey patch socket, I do not get these errors and
everything works fine. My question is, what does this assertion
indicate? Is it something I'm doing? Some issue in Thrift?

Thanks,
Alec

--
I think I see the problem. The problem is that you are wrong.

Denis Bilenko

unread,
Jun 20, 2010, 8:08:13 AM6/20/10
to gev...@googlegroups.com
Hi Alec,

Unlike 0.12.2, socket in the current dev version does not allow more
than one greenlet to recv or send. (It's OK to receive in one greenlet
and send in another). This helped to fix issue #26
(http://code.google.com/p/gevent/issues/detail?id=26).

This might break compatibility with stdlib sockets.
On the other hand, it seems that if you have two or more
receivers(senders) on one socket most likely it's a logic error.

Whether it's caused by your code or by Thrift is hard to guess without
knowing the details. Can you post a minimal example that reproduces
the error? Also, please post the complete tracebacks.

Cheers,
Denis.

Alec Thomas

unread,
Jun 20, 2010, 8:31:50 AM6/20/10
to gev...@googlegroups.com
On 20 June 2010 22:08, Denis Bilenko <denis....@gmail.com> wrote:
> Hi Alec,
>
> Unlike 0.12.2, socket in the current dev version does not allow more
> than one greenlet to recv or send. (It's OK to receive in one greenlet
> and send in another). This helped to fix issue #26
> (http://code.google.com/p/gevent/issues/detail?id=26).
>
> This might break compatibility with stdlib sockets.
> On the other hand, it seems that if you have two or more
> receivers(senders) on one socket most likely it's a logic error.

Okay, that makes sense.

> Whether it's caused by your code or by Thrift is hard to guess without
> knowing the details. Can you post a minimal example that reproduces
> the error? Also, please post the complete tracebacks.

Given your description of what the error means, I added locking around the Thrift client code, as it can and will be called by different WSGI requests in different greenlets. This fixed the issue, and obviously a potential bug!

Thanks again Denis.
Reply all
Reply to author
Forward
0 new messages