Recommended way to force a thread context switch?
Lloyd Zusman
ljz at asfast.com
Sat Jan 6 16:53:23 EST 2007
Duncan Booth <duncan.booth at invalid.invalid> writes:
> Lloyd Zusman <ljz at asfast.com> wrote:
>
>> I have a python (2.5) program with number of worker threads, and I want
>> to make sure that each of these does a context switch at appropriate
>> times, to avoid starvation. I know that I can do a time.sleep(0.001) to
>> force such a switch, but I'm wondering if this is the recommended
>> method.
>
> The recommended method is to start a new thread rather than following up on
> an existing thread with an unrelated question.
I accidentally hit "a" in my mailer instead of "w" ("reply" instead of
"compose"). Geez. It was an accident. I'm sorry.
> Why do you think that just letting the threads run won't have the effect
> you desire? Leave it to the system to schedule the threads.
I can already see that they don't have the effect I desire. They are
long numerical calculations in tight loops. I have to periodically put
explicit time.sleep(0.001) calls in place to force the context
switching, and I was wondering if that's the recommended method.
--
Lloyd Zusman
ljz at asfast.com
God bless you.
More information about the Python-list
mailing list