• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

threads in python

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Here's a snippet from the book Head First Python:

"Threads do indeed exist in Python but should be avoided where possible.
This has nothing to do with the quality of Python’s threading library and
everything to do with Python’s implementation, especially the implementation
known as CPython (which is more than likely the one you’re running
now). Python is implemented using a technology known as the Global
Interpreter Lock (GIL), which enforces a restriction that Python can only
ever run on a single interpreter process, even in the presence of multiple
processors. What all this means to you is that your beautifully designed and implemented
program that uses threads will never run faster on multiple processors even
if they exist, because it can’t use them. Your threaded application will run
serially and, in many cases, run considerably slower than if you had developed
the same functionality without resorting to threads.
Main message: don’t use threads with Python until the GIL restriction is
removed…if it ever is."

Does that mean that usually one uses threading in python only when the application has both IO-Bound and CPU-Bound activities?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For CPython, yes. But if you are using a different implementation of Python, it may have a different threading system which makes full multi-threaded applications possible. For example Jython uses Java's underlying threading library, and IronPython uses .NET's threading library, making them both implementations that are not limited by the GIL.
 
reply
    Bookmark Topic Watch Topic
  • New Topic