python threading and timing

Oeyvind Brandtsegg obrandts at gmail.com
Sun Oct 1 16:28:10 EDT 2006


hello

I'm writing a Python application for live music performance/improivsation,
using csound as the synthesis engine, and Python for compositional
algorithms, GUI and control.

I creating several threads:
one for GUI
one for csound,
one for a timed queue (timed automation events),
one for communication with a tcp based sensor interface.

My threads do not share data,
I use threads merely to enable several processes to run in paralell.
I think I do not need to use locks to control threads in this case,
but I'm not sure (?)

Also, I wonder what method I should be using to get a precise timing
in my automation thread (acting as a sequencer).

I've attached two simple examples of different ways I could implement threads.
The only task in these examples is to generate timed counters, but the
general procedure would be the same for more complex timed tasks.
One example uses time.sleep() to release a thread's interpreter lock,
and at the same time provide the time interval until the next
iteration.
The other example uses a thread event wait() call.

It seems that the example using wait() does not provide the same
precision as time.sleep() does (the counters does not sync, e.g. a
counter with a time interval of 0.1 does not count 10 times as fast as
a counter with a time interval of 1 second.

Any insights on how to do this the best way (thread safety and time
precision) would be greatly appreciated.

best
Oeyvind Brandtsegg
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ThreadingAndControl_sleep.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20061001/f1d6f2ac/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ThreadingAndControl_wait.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20061001/f1d6f2ac/attachment-0001.ksh>


More information about the Python-list mailing list