aspose file tools*
The moose likes Jython/Python and the fly likes threads in python Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "threads in python" Watch "threads in python" New topic
Author

threads in python

Rodrigo Bossini
Ranch Hand

Joined: Jul 03, 2009
Posts: 113
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?


I see wind mills
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
 
wood burning stoves
 
subject: threads in python