Hello Phil.

I was impressed with the python coroutines idea and wrote small
implementation for the PyQt: http://github.com/ddosoff/pyqtcoroutines

Nonpreemptive multithreading programs looks synchronous:

from pyqtcoroutines.coroutines import Scheduler

# coroutine example
def inserter( a_lot_of_records ):
    try:
        for record in a_lot_of_records:
            # do small piece of work here

            ... insert one record to the sql database ...

            # This is execution trap
            #
            # Unlike QCoreApplication.processEvents()
            # we do not call new restricted event loop,
            # we will NORMALLY RETURN to the main qt event loop!

            yield
    except:
        # handle all exceptions in synchronous manner
        ...


# create scheduler to execute our inserter(..) later
s = Scheduler()

# It's not the inserter() call!
# We construct the built-in python Generator object!
#
# Execution will start after the first
# coroutine.send( None ) call inside the Scheduler.
coroutine = inserter( a_lot_of_records )

# Let the Scheduler to start execution of
# inserter(..) later inside the main qt event loop.
s.newTask( coroutine )

Full example : http://github.com/ddosoff/pyqtcoroutines
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to