[clug-talk] Moving CPU Intensive Thread to lower Priority?
Mark Carlson
carlsonmark at gmail.com
Wed Mar 18 08:37:43 PDT 2009
On 3/18/09, simon at mungewell.org <simon at mungewell.org> wrote:
> Hi all,
> I have a question this week about thread priority, the little python
> application I am writing is CPU bound (on my crappy old machine).
>
> I have split the application into threads (using threading) which appears
> to work OK, but the application is still responding at the speed of the
> slowest thread.
>
> The app is a video processing/display, I have:
> --
> Main Thread: pyGTK display/buttons.
> Capture Thread: grab from V4L2 and render onto display.
> Process Thread: grab image from Capture thread and process, processing is
> done using a wrapper to C library.
> --
>
> The video display framerate drops to that of the processing thread and the
> CPU is pegged at 100%. If I disable the processing thread then the video
> is smooth, with the correct framerate and CPU is mostly idle.
>
> If I put a large sleep (5s for example) in the processing thread I get
> slow video (whilst processing) and then smooth video (whilst sleeping), so
> I believe that I have done the threading correctly.
>
> So my questions are:
> Is there a way to lower the priority of the 'Process Thread' so that it
> does not run as intensively?
> Or, is there a way to increase the rate at which the 'Process Thread' is
> swapped out and thus allowing the other (less intensive) threads to get
> CPU time?
>
> Cheers,
> Simon.
If possible, I would suggest trying to use the Popen2 module. This
way, you should be able to re-nice it (os.nice) after the fork. This
may be easy or painful depending on how much the thread needs to talk
to it's parent.
-Mark C.
More information about the clug-talk
mailing list