Home arrow Python arrow Basic Threading in Python

Basic Threading in Python

If you want your application to perform several tasks at once, you can use threads. Python can handle threads, but many developers find thread programming to be very tricky. Among other points, Peyton McCullough covers how to spawn and kill threads in this popular language.

TABLE OF CONTENTS:
  1. Basic Threading in Python
  2. Using the Threading Module
  3. Pooling Threads
  4. More Thread Tricks
By: Peyton McCullough
Rating: starstarstarstarstar / 157
April 04, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

Threads allow applications to perform multiple tasks at once. Multi-threading is important in many applications, from primitive servers to today's complex and hardware-demanding games, so, naturally, many programming languages sport the ability to deal with threads. This includes Python.

However, Python's support for multi-threading is not without limitations and consequences, as Guido van Rossum writes:

"Unfortunately, for most mortals, thread programming is just Too Hard to get right.... Even in Python -- every time someone gets into serious thread programming, they send me tons of bug reports, and half of them are subtle bugs in the Python interpreter, half of them are subtle problems in their own understanding of the consequences of multiple threads...."

Before we begin to look at the code that makes threading work, the most important feature we must look at is Python's global interpreter lock. If two or more threads were to attempt to manipulate the same object at the same time, problems would inevitably pop up. The global interpreter lock fixes this. Only one thread can perform an action at any given time. Python automatically switches between threads when it is needed.



 
 
>>> More Python Articles          >>> More By Peyton McCullough
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: