Threads in Python

Gordon McMillan gmcm at hypernet.com
Mon Feb 14 16:59:51 CET 2000


Warren Postma wrote:
 
[Aahz]
> > As Fredrik said, yes and no.  Threads are incredibly easy to use in
> > Python; the biggest drawback is the Python global interpreter lock,
> > which means that only one thread can run Python code at any time.
> > That's usually not a big drawback, because threading is usually used to
> > optimize I/O, and extension libraries (including I/O) can release the
> > global lock.
> 
> What about pre-emption? Can the Python interpreter pre-emptively switch
> threads
> between any two lines of Python code? Is there a "Schedule()" call to force
> a thread to
> give up it's timeslice?

Python threads get sliced every N Python instructions (default 
10). time.sleep(0.001) will force a yield.

- Gordon




More information about the Python-list mailing list