Thank for the reply.
I have no idea about the behaviour regarding the GIL.

But I found that my problem is due to the python wrapper: this is not a bug
but it cannot allow threading.
What happens is that the python 'dispatch' call the underlying C 'dispatch'
(of course) in one python thread. But doing that, python do not control any
more this thread, and thus the interpreter is blocked by this call.
If I add a timer event in the loop with a callback doing nothing
(createTimer(lambda fd,evt,obj: sleep(0)).addToLoop(timeout=0)), the C code
call back the python code and the other trheads can be executed ... but why
use event if there is a loop on null timer doing nothing!?!
So, if there is nothing that can be made in the wrapper for that (I have
absolutely no idea), I guess I have to discard either threading either
libevent of my program.

Which lead me to another question about architecture design.
My first (libevent) thread is a socket server, getting requests from all
clients, and putting them in a queue. My second thread take request one by
one, processes it, and create a reply that it put in a queue used by the
first thread. I wanted 2 threads (or 2 thread pool) because the application
logic of the second thread imply accessing the DB and doing a fair bit of
computation that is not easy to split in events in such a way that we can
ensure the response time.
If I give up the threading, I could have the same model using processes, but
then I need a communication channel between the 2 processes. What can be
used which would be efficient? UNIX socket? mkfifo?
My other alternative is to replace libevent by the twisted framework which
allow an event based server model, but threading for non asynchronous calls.

Any comments?
On 6/8/07, Ka-Hing Cheung <[EMAIL PROTECTED]> wrote:

On Thu, 2007-06-07 at 16:02 +0800, Ludovic Coquelle wrote:
> Hi,
>
> I use libevent through the libevent-python wrapper.
> If it is not the relevant mailing list to ask, please point me to the
> right place ;)
>
> I wanted to write an event loop, running in its own thread, while
> another thread can do something else.
> Whatever I've tried, the first call to 'dispatch' block all the others
> threads (from what I understand).
> I wrote something like:
>
> def evhello(obj, name):
>     # dummy callback: print hello every second
>     print "hello", name
>     if obj:
>         obj.addToLoop(timeout=1)
>
> def evstart(name, next=None):
>     evB = libevent.EventBase() # new base for each thread
>     event = libevent.createTimer(lambda fd, events, obj: evhello(obj,
> name))
>     event.setEventBase(evB)
>     event.addToLoop(timeout=1)
>     evB.dispatch()

Does dispatch() here give up the global interpreter lock?

-khc


_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to