An Introduction to Stackless Python
Stackless Python is modified version of CPython with support for tasklets; also called microthreads, fibers or green threads. Tasklets are an additional way to implement multithreading but with much lower overhead than system threads. They take fewer system resources so a Stackless environment may have tens of thousands of active tasklets instead of at most a few hundred threads. Context switching and inter-tasklet communication via "channels" are fast, making Stackless a useful platform for developing dense multitasking systems.
The talk is meant for a intermediate level Python programmer who had heard about Stackless and wants to know why and when people use it. I will cover the basics of the Stackless API: starting tasklets, exchanging data and participating in its default collaborative scheduler. I'll show how to implement a standard boss/worker architecture then expand that to handle a simulation environment with a UI interface. I'll demonstrate how to use
Stackless and an asynchronous I/O library to emulate blocking function calls so that existing blocking code works with Stackless' default collaborative scheduler.
Concepts to Cover
- lightweight threads
- async I/O
- sync I/O
- measuring, scheduling time
- shifting priorities among threads
- debugging your constellation of threads
Questions to Answer
- Doesn't the addition of bidirectional generations to Python 2.5 render Stackless obsolete?
- Isn't Stackless specific to CPython and lock me out of other implementations of Python, such as Jython, IronPython, Pirate (Parrot/Perl6) and PyPy?