Threading is actually fair

Matt Kimball matt at kimball.net
Tue May 21 11:06:31 EDT 2002


Okay, Tim was right, of course.  Python's global interpreter lock wasn't the
cause of any of my complaints about threading unfairness.  

For those interested, part of the problem was that my background computation
thread was flooding my GUI with "update" events, telling my main GUI thread that
it had new data and wanted to repaint its views of said data.  I throttled that
back so that it doesn't send an update more frequently than every 100 ms and it
helped a bit.

The second half of the solution was actually to set the thread priority of my
background computation to something lower than the GUI thread.  This made the
GUI responsiveness much, much better.  Using win32all, in my background
computation thread, I do this before any of the real work:

win32process.SetThreadPriority(win32api.GetCurrentThread(), 
                               win32process.THREAD_PRIORITY_BELOW_NORMAL)

And from there on out, things run very smoothly.

-- 
Matt Kimball
matt at kimball.net







More information about the Python-list mailing list