Hello Phil.<div><br></div><div>I was impressed with the python coroutines idea and wrote small implementation for the PyQt: <a href="http://github.com/ddosoff/pyqtcoroutines">http://github.com/ddosoff/pyqtcoroutines</a></div>
<div><br></div><div>Nonpreemptive multithreading programs looks synchronous:</div><div><br></div><div><div>from pyqtcoroutines.coroutines import Scheduler</div><div><br></div><div># coroutine example</div><div>def inserter( a_lot_of_records ):</div>
<div>    try:</div><div>        for record in a_lot_of_records:</div><div>            # do small piece of work here </div><div><br></div><div>            ... insert one record to the sql database ...</div><div><br></div><div>
            # This is execution trap</div><div>            #</div><div>            # Unlike QCoreApplication.processEvents() </div><div>            # we do not call new restricted event loop,</div><div>            # we will NORMALLY RETURN to the main qt event loop!</div>
<div><br></div><div>            yield</div><div>    except:</div><div>        # handle all exceptions in synchronous manner</div><div>        ...</div><div><br></div><div><br></div><div># create scheduler to execute our inserter(..) later</div>
<div>s = Scheduler()</div><div><br></div><div># It's not the inserter() call!</div><div># We construct the built-in python Generator object!</div><div>#</div><div># Execution will start after the first </div><div># coroutine.send( None ) call inside the Scheduler.</div>
<div>coroutine = inserter( a_lot_of_records )</div><div><br></div><div># Let the Scheduler to start execution of </div><div># inserter(..) later inside the main qt event loop.</div><div>s.newTask( coroutine )</div></div><div>
<br></div><div>Full example : <a href="http://github.com/ddosoff/pyqtcoroutines">http://github.com/ddosoff/pyqtcoroutines</a></div>