[clug-talk] Moving CPU Intensive Thread to lower Priority?

Mark Carlson carlsonmark at gmail.com
Wed Mar 18 13:16:43 PDT 2009


On 3/18/09, simon at mungewell.org <simon at mungewell.org> wrote:
>
>  > --
>  > Basically, just wrap I/O blocking code or CPU-intensive code in the
>  > following macros:
>  >   Py_BEGIN_ALLOW_THREADS
>  >     ...Do some time-consuming operation...
>  >   Py_END_ALLOW_THREADS
>  > --
>  >
>
>
> So I couldn't wait, over lunch I fired up the trusty live CD, installed
>  all the build dependancies and borrowed a webcam from my colleague...
>
>  and yes, these macros make a huge difference to responsiveness of the
>  gui/display.
>
>  Cool, eh.
>  Simon.

Sorry, I didn't realize your code was in C.  Yes, those macros are
needed, otherwise no other python threads will run while your code is
being executed!  In addition to wrapping functions that just take a
lot of time, you should also wrap everything that could possibly block
(including printf, and all blocking socket operations)

-Mark C.



More information about the clug-talk mailing list