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&#39;ve tried, the first call to &#39;dispatch&#39; 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;">&nbsp;&nbsp;&nbsp;  # dummy callback: print hello every second</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; print &quot;hello&quot;, name</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; if obj:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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;">&nbsp;&nbsp;&nbsp; evB = libevent.EventBase() # new base for each thread</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; 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;">
&nbsp;&nbsp;&nbsp; event.setEventBase(evB)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; event.addToLoop(timeout=1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp;&nbsp;&nbsp; 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, &#39;toto&#39;))
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">t1 = threading.Thread(target=evstart, args=(&#39;toto&#39;,))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">t2 = threading.Thread(target=evstart, args=(&#39;titi&#39;,))</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>