Hi,<br><br>I use libevent through the libevent-python wrapper.<br>If it is not the relevant mailing list to ask, please point me to the right place ;)<br><br>I wanted to write an event loop, running in its own thread, while another thread can do something else.
<br>Whatever I've tried, the first call to 'dispatch' block all the others threads (from what I understand).<br>I wrote something like:<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
def evhello(obj, name):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> # dummy callback: print hello every second</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> print "hello", name</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if obj:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> obj.addToLoop(timeout=1)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
def evstart(name, next=None):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> evB = libevent.EventBase() # new base for each thread</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> event = libevent.createTimer(lambda fd, events, obj: evhello(obj, name))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
event.setEventBase(evB)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> event.addToLoop(timeout=1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
evB.dispatch()</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">t0 = threading.Thread(target=evhello, args=(None, 'toto'))
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">t1 = threading.Thread(target=evstart, args=('toto',))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">t2 = threading.Thread(target=evstart, args=('titi',))</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">t0.start()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
time.sleep(3)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># t0 is effectively running ...</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">t1.start()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
time.sleep(3)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># t1 event loop is running ... but t0 STOPed!!!</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">t2.start()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># ... never reach</span><br style="font-family: courier new,monospace;">
<br><br>Anybody has a clue on the problem?<br>Is it normal behaviour?<br>Am I doing something wrong?<br>