[Libevent-users] event loop stop the other threads

Ludovic Coquelle lcoquelle at gmail.com
Thu Jun 7 04:02:37 EDT 2007


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()

t0 = threading.Thread(target=evhello, args=(None, 'toto'))
t1 = threading.Thread(target=evstart, args=('toto',))
t2 = threading.Thread(target=evstart, args=('titi',))

t0.start()
time.sleep(3)
# t0 is effectively running ...

t1.start()
 time.sleep(3)
# t1 event loop is running ... but t0 STOPed!!!

t2.start()
# ... never reach


Anybody has a clue on the problem?
Is it normal behaviour?
Am I doing something wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://monkeymail.org/archives/libevent-users/attachments/20070607/8282c3c8/attachment-0001.htm


More information about the Libevent-users mailing list