Final Comments on Threads

Python threads are quite functional

  • Can write applications that use dozens (or even hundreds) of threads

But there are performance issues

  • Global interpreter lock makes it difficult to fully utilize multiple CPUs.
  • You don't get the degree of parallelism you might expect.

Interaction with C extensions

  • Common problem: I wrote a big C extension and it broke threading.
  • The culprit: Not releasing global lock before starting a long-running function.

Not all modules are thread-friendly

  • Example: gethostbyname() blocks all threads if nameserver down.
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 81
July 17, 2000, beazley@cs.uchicago.edu
>>>