Priority based concurrent execution

Jean-Paul Calderone exarkun at divmod.com
Thu Sep 21 09:07:44 EDT 2006


On 21 Sep 2006 04:56:46 -0700, "Doug.Fort at gmail.com" <doug.fort at gmail.com> wrote:
>
>Willi Richert wrote:
>> Hi,
>>
>> I have a simulation application (PlayerStage) in which the robot is asked
>> every ~200ms for an action. In the meantime the robot has to do some
>> calculation with the perception. As the calculation gets more and more time
>> consuming I am thinking about outsourcing it into a concurrently running
>> method. If the calculation takes too long it would be ok for the result to be
>> incorporated in some future cycle of the main loop, resulting in the
>> calculation being done less and less often and the main loop executing some
>> stop behavior.
>> My question: Is there a possibility in Python (either with the threading
>> module or with Twisted's non-threading style) to prioritize the two
>> (pseudo-)concurrent methods so that the main tread is further on executed
>> every ~200ms and the calculation thread being executed only in "idle" time
>> slots?
>>
>> Thanks,
>> wr
>
>Hi,
>
>I suggest taking a look a PEP 342
>http://www.python.org/dev/peps/pep-0342/. The new coroutines capability
>in Python 2.5 seems to be intended for exactly what you are doing.

Note that the title of the PEP is misleading and coroutines have not been
introduced in Python 2.5.

Generators (either pre-2.5 or post-2.5) can be used as an application
API to an implementation of something like what the poster is requesting,
inasmuch as many people find them to be a useful way to split a task up
into small pieces.  However, aside from syntactic convenience, they don't
really bring anything fundamentally different to the table.

Jean-Paul



More information about the Python-list mailing list