gevent.Queue communication from other python threads

302 views
Skip to first unread message

Neilen Marais

unread,
May 15, 2012, 5:18:40 AM5/15/12
to gevent: coroutine-based Python network library
Hi,

Is it possible to communicate to a gevent tasks from another thread
via gevent.Queue? I have to interact with other threaded libraries
involving callbacks, and would like to use an actor like pattern where
each callback from another thread puts something on the gevent based
actor's queue.

Thanks
Neilen

Paul Giannaros

unread,
May 15, 2012, 4:09:05 PM5/15/12
to gev...@googlegroups.com
Under unix you can use non-blocking pipes (os.pipe/fcntl) – write to the pipe from your thread and gevent.select the pipe from a greenlet. I'd be interested to hear if there's a better way though, particularly one that works under windows. 

Denis Bilenko

unread,
May 15, 2012, 4:27:54 PM5/15/12
to gev...@googlegroups.com
On Tue, May 15, 2012 at 1:18 PM, Neilen Marais <nma...@ska.ac.za> wrote:
> Is it possible to communicate to a gevent tasks from another thread
> via gevent.Queue? I have to interact with other threaded libraries
> involving callbacks, and would like to use an actor like pattern where
> each callback from another thread puts something on the gevent based
> actor's queue.

No, it's not possible. Nothing is thread-safe in gevent except for
stuff in threadpool.py and async watcher.

On Wed, May 16, 2012 at 12:09 AM, Paul Giannaros
<p.a.gi...@gmail.com> wrote:
> Under unix you can use non-blocking pipes (os.pipe/fcntl) – write to the
> pipe from your thread and gevent.select the pipe from a greenlet. I'd be
> interested to hear if there's a better way though, particularly one that
> works under windows.

Use the async watcher instead. It is also cross platform.

To find more about async watcher search this group:
http://groups.google.com/group/gevent/search?group=gevent&q=async+watcher&qt_g=Search+this+group
Reply all
Reply to author
Forward
0 new messages