Python Threads

Python supports threads on the following platforms

  • Solaris
  • Windows
  • Systems that support the POSIX threads library (pthreads)

Thread scheduling

  • Tightly controlled by a global interpreter lock and scheduler.
  • Only a single thread is allowed to be executing in the Python interpreter at once.
  • Thread switching only occurs between the execution of individual byte-codes.
  • Long-running calculations in C/C++ can block execution of all other threads.
  • However, most I/O operations do not block.

Comments

  • Python threads are somewhat more restrictive than in C.
  • Effectiveness may be limited on multiple CPUs (due to interpreter lock).
  • Threads can interact strangely with other Python modules (especially signal handling).
  • Not all extension modules are thread-safe.
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 67
July 17, 2000, beazley@cs.uchicago.edu
>>>