This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "threads in python" Watch "threads in python" New topic

threads in python

Rodrigo Bossini
Ranch Hand

Joined: Jul 03, 2009
Posts: 113

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

Joined: Jan 28, 2003
Posts: 4168

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.

subject: threads in python
Similar Threads
Multithreading: Usage scenarios
JVM & Java Threads Scheduling
Embedded Scripting Languages: Success Stories? Jython?
Does the OS has any knowledge about threads ?
Native versus Greed