Recommended way to force a thread context switch?

Lloyd Zusman ljz at asfast.com
Sat Jan 6 18:01:04 EST 2007


Duncan Booth <duncan.booth at invalid.invalid> writes:

> [ ... ]
>
> If the context isn't switching enough for you then try calling 
> sys.setcheckinterval(n) with varying values of n until you find one which 
> is suitable. Calling it with a lower value of n will increase the frequency 
> that you switch thread contexts, although of course it will also increase 
> the overall runtime for your program.

Thank you very much.  The sys.setcheckinterval function is what I need.
It seems that the original writer of the app had set this interval to a
high value in a part of the code that I overlooked until you mentioned
this right now.


> [ ... ]
>
> Why does it matter whether individual threads are being 'starved'? Surely 
> you want them all to complete in any case, so does it matter if they run 
> sequentially or in parallel?

Because some of the threads perform monitoring and notification that
need to occur in a timely fashion.  Since these threads are doing IO,
they switch context appropriately, but once one of the big
number-crunching threads gets control, it starves out the monitoring
threads, which is not a good thing for my app ... or at least it did
so with the original large checkinterval.


-- 
 Lloyd Zusman
 ljz at asfast.com
 God bless you.




More information about the Python-list mailing list