Preemption in python

Evan Klitzke evan at
Sun Sep 23 20:31:51 CEST 2007

On Sat, 2007-09-22 at 19:28 -0700, Kurtis Heimerl wrote:
> Hi, I'm developing my first python application, a multi-threaded cell
> phone gadget on ubuntu 7.10. I've just split off my first thread, and
> I've noticed something extremely strange: There doesn't seem to be any
> preemption. There are currently two threads, one that pings a storage
> service to see if there are messages available, and the other that
> runs the gtk windows. If I do not explicitly yield either one, it runs
> forever. I'm assuming this is a setting somewhere, but that's a very
> strange default behavior. 
> How do I get this to go about preempting these threads? Any advice
> would be helpful. Thanks!

I'm far from an expert in threaded Python applications, but threading
ought to work out of the box. By default the Python interpreter will
switch threads every 100 bytecode instructions

Note that if you are synchronizing around a lock, you may need to sleep
before trying to reacquire the the lock to completely exit the critical
section. A good overview of this (and the Python threading model) can be
found at

Evan Klitzke <evan at>

More information about the Python-list mailing list