Help with Optimization of Python software: real-time audio controller

Klaas mike.klaas at gmail.com
Mon Feb 12 17:17:03 EST 2007


On Feb 11, 6:40 pm, craiglewis... at gmail.com wrote:
> Currently, I have all of the above "working", although I'm running
> into some serious timing issues.  When I run the program, I get
> irregular timing for my metronome (if it sounds at all), as well as
> irregular timing in writing to the external device.  It's extremely
> crucial that threads #1 & #2 are executed as close to real-time as
> possible, as they form the "core" of the song, and their elements
> can't be delayed without "messing" the song up considerably.
>
> I've read up quite a bit on different optimization methods in Python,
> but am not sure which direction to head.  I've checked out profile,
> Psyco, Pyrex, as well as just porting everything over to C.  Since I'm
> on a Mac (Power PC), I can't use Psyco.  And doing any of the others
> seemed like a big enough project that I should really ask someone else
> before I embark.

Your problems do not necessarily stem from slow code.  Python only
performs thread context switches every 100 øpcodes, and the switch
might not arrive at the right time.

You can lower this value (sys.setcheckinterval).  Your computationally-
intensive threads may effectively lower their priority by calling
time.sleep(.00001) every so often.

Ultimately, maintaining explicity control over the scheduling of
events is probably the way to go.

Pyrex is my preferred optimization method, but it can take some
knowledge of what's going on to get the most out of it.  numpy is
another option.

-Mike




More information about the Python-list mailing list