access gevent loop

52 views
Skip to first unread message

jsia

unread,
Mar 28, 2016, 8:40:35 AM3/28/16
to gevent: coroutine-based Python network library
Hi,

I'm using gevent.1.1, however I want to use hiredis libev integration to gevent


However, as you can see redisLibEvAttach needs the ev_loop * as the parameter for it to use the same ev_loop * as gevent.  I've checked the property ptr in the loop object it's only a <size_t>,  how is it possible for me to share the event loop that gevent is using?

Thanks,
Jason

Jason Madden

unread,
Mar 28, 2016, 8:52:56 AM3/28/16
to gev...@googlegroups.com
There is no documented portable way to access the libev loop that a particular gevent.core.loop object is using; the details differ depending on which gevent.core implementation is in use.

However, most of the time, *after* the gevent.core.loop implementation is up and running, you can probably get what you're after from the C function `ev_default_loop()`.

gevent may have to be build to *not* embed libev in order for you to have access to that symbol (i.e., it needs to link to the system libev).

This is not a tested scenario so I don't know what the outcome will be. Things may just work or they may crash in spectacular fashion. Good luck!

~Jason

jsia

unread,
Mar 28, 2016, 9:40:59 AM3/28/16
to gevent: coroutine-based Python network library
It was working before with the old gevent 0.13 since it exposes the current_base pointer.  I tried editing the property ptr to return <object> self._ptr instead of <size_t> self._ptr but of course seg fault lol.  I tried to do 

from gevent.hub import Hub

redisLibEvAttach( <libev.ev_loop *> Hub().loop.ptr, self.ctx)

Jason Madden

unread,
Mar 28, 2016, 9:44:52 AM3/28/16
to gev...@googlegroups.com

> On Mar 28, 2016, at 08:40, jsia <jsi...@gmail.com> wrote:
>
> It was working before with the old gevent 0.13 since it exposes the current_base pointer. I tried editing the property ptr to return <object> self._ptr instead of <size_t> self._ptr but of course seg fault lol. I tried to do
>
> from gevent.hub import Hub
>
> redisLibEvAttach( <libev.ev_loop *> Hub().loop.ptr, self.ctx)

gevent 0.13 was based on libevent, not libev. gevent 1.0 and newer use libev (which provides the `ev_default_loop()` function) so there are numerous architectural differences.
Reply all
Reply to author
Forward
0 new messages