libev loop in a Python thread

Jonas H. jonas at
Sun Jun 6 22:18:34 CEST 2010

hello there,

I have written a small standalone Python web server in C using libev.
I want to run it within a Python thread to make it possible to share 
memory easily.

Unfortunately it seems like the thread that runs the libev mainloop 
blocks any other Python thread:  Once the libev loop has been started, 
code in other threads won't be executed any more.  If I send a request 
to the server -- so the libev thread leaves the libev loop code and 
enters my web server C code -- other Python threads' code is executed. 
Until the C code re-enters the libev code.

I tried threading priorities, but that didn't change anything.
Changing the backend doesn't change anything, either (I tried epoll and 

I debugged around a little bit and found out that the other Python 
threads all stop some mystic `sem_wait`.  Not that this is something to 
worry about -- but could it be that something deadlocks there?  Or is it 
just libev that doesn't give the poor(ly implemented) Python interpreter 
a chance of taking back control? ;-)

I'm glad about any suggestions on how to fix this stuff.



PS: If you want code:

   git clone git://
   cd bjoern
   make get-http-parser
   python tests

More information about the libev mailing list