<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=US-ASCII">
<META content="MSHTML 6.00.2900.2802" name=GENERATOR></HEAD>
<BODY id=role_body style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Arial" 
bottomMargin=7 leftMargin=7 topMargin=7 rightMargin=7><FONT id=role_document 
face=Arial color=#000000 size=2>
<DIV>&nbsp;</DIV>
<DIV>Hi, I think it might be a common question about integrating stackless and 
other event driven framework. In most cases, the other event driven framework 
uses main loop and listening on select() or poll() calls like this:</DIV>
<DIV>&nbsp;</DIV>
<DIV>while ( forever&nbsp; ) {</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; add event queue 1 unix domain socket to file descriptor 
sets<BR>&nbsp;&nbsp;&nbsp; add event queue 2 unix domain socket to file 
descriptor sets<BR>&nbsp;&nbsp;&nbsp; ... <BR>&nbsp;&nbsp;&nbsp; add tcp 
connection 1 to file descriptor sets<BR>&nbsp;&nbsp;&nbsp; add tcp connection 2 
to file descriptor sets<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; select( 
file descriptor sets 1 ) ; // block here and wait for any event (fd status) 
change</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; check which file descriptor has been changed and process 
that event<BR>&nbsp;&nbsp;&nbsp; ...<BR>}</DIV>
<DIV>&nbsp;</DIV>
<DIV>I have a C++ event driven main loop framework that embedded the stackless 
framework. <BR>The only way I can make these two framework work together is: 
switching between two frameworks in a fix time range.</DIV>
<DIV>&nbsp;</DIV>
<DIV>1. timeout the select() call in my C++ main loop every few hundreds 
milliseconds, <BR>2. give a few hundress millisecond for stackless code to 
run:<BR>&nbsp;&nbsp; watchdogHandle = 
handle&lt;&gt;(allow_null(PyStackless_RunWatchdog(1000)));<BR>3. go back to the 
C++ main loop and block on select() again</DIV>
<DIV>&nbsp;</DIV>
<DIV>This way works but not so elegant. It might be idle and waste a few hundred 
millisecond per loop in one framework while the other framework has work waiting 
for it to do.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I am thinking a "perfect" model will be ...</DIV>
<DIV>&nbsp;</DIV>
<DIV>If stackless internally is also blocking on a select( fdset2 ) call, we can 
add a stackless API to export that file descriptor set (fdset2).<BR>Then we can 
merge two select() calls of two main loops into a single select( fdset1+ fdset2 
) call. We can then listen to all events in one blocking select call.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I would like to hear any suggestion / experience in this area. Thanks a 
lot.</DIV>
<DIV>&nbsp;</DIV>
<DIV>- Jim</DIV>
<DIV>&nbsp;</DIV></FONT></BODY></HTML>