|
|
An introduction for newcomers
Stackless Python is an enhanced version of the Python programming language. It allows programmers to reap the benefits of thread-based programming without the performance and complexity problems associated with conventional threads. The microthreads that Stackless adds to Python are a cheap and lightweight convenience which can if used properly, give the following benefits:
- Improved program structure.
- More readable code.
- Increased programmer productivity.
Stackless Documentation
In the repository, you will find documentation gathered from the internet related to Stackless design, presentations and tutorials.
Stackless Usage
In this project we aim to have usage examples with Stackless from beginners to real life problems.
Here follows links to examples for features found in Stackless Python. There are examples where only Stackless is used and pages dedicated for Stackless integration with external frameworks like Twisted and PyQt.
- StacklessNonblockModules - Socket and file nonblocking modules
- StacklessThreads - Examples integrating stackless with python threads
- StacklessNetworking - Examples using socket via nonblocking stacklesssocket module.
- StacklessWSGI - Examples implementing a WSGI compliant server and applications.
- StacklessTwisted - Twisted integration with stackless
- StacklessGUI - GUI integration (PyQt, etc)
Factorial
Factorial example using stackless to break Python's recurtion limit of 1000
factorial.py - Download
Producer - Consumer
This example illustrates a producer - consumer chain where each agent runs on its tasklet. We a tasklet that take care of sleep calls.
producerConsumerTextmode.py - Download
There is also a version of producer/consumer example based on BeNice and alternative schedule approach (See below).
producerConsumerAlternativeSched.py - Download
Tasklet Pickling
Tasklets can be pickled to a string or file and then unpickled to have its state restored even in another machine.
pickleChannels.py - Download
Channel With Timeout
The channel implemented here can have a timeout so the tasklets that are waiting on it receives an exception when its timeout expires.
channelWithReceiveTimeout.py - Download
Normal Scheduling
This example shows the basic usage of Stackless and shows a function that combined with its manager handles sleeping tasklets.
scheduleNormal.py - Download
Alternative Scheduling
Here there is an alternative approach on scheduling:
Benefits of this approach:
- It lends itself well to embedding, if implemented in C or C++. - It allows more precise control.
Limitations of this approach:
- The expectation is that the scheduler will be empty because of this
will exit pretty much immediately. So anything which calls to 'stackless.schedule' rather than using 'BeNice' or 'Sleep' will break this scheduling model and prevent it from working as expected. After all, if there are tasklets in the scheduler it continues to run and does not exit.
Ideally 'stackless.schedule' should be patched to call BeNice. Or calls to it just avoided completely.
scheduleAlternative.py - Download
Sign in to add a comment
