Stackless Python for Python 2.5 is now available. What is Stackless Python? ========================= 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 and channels that Stackless adds to Python are cheap and lightweight conveniences which can if used properly, allow clearer and more readable code and the ability to dispatch with messy and awkward boilerplate like callbacks or the new generator coroutines. Where can I get it? =================== The source code can be obtained from the SVN repository which can be found here: http://svn.python.org/projects/stackless/branches/release25-maint/ Precompiled Windows binaries can be found here: http://www.stackless.com/download How might I benefit from using Stackless Python? ================================================ The most useful example is the replacement socket module. This allows all socket operations to be used in parallel, no longer blocking the rest of your application, or requiring you to use threads or libraries like asyncore yourself. Monkeypatch this library in place of the one in the standard library and all modules which use the standard socket module gain the same benefit. http://www.stackless.com/wiki/Examples -->8--[ asynch_fetch.py: example code courtesy of Andrew Dalke ]--8<-- import sys import stacklesssocket import stackless sys.modules["socket"] = stacklesssocket import urllib import time def download(uri): t1 = time.time() f = urllib.urlopen(uri) s = f.read() t2 = time.time() print "Downloaded", uri, "in", "%.1f" % (t2-t1), "seconds" return t2-t1 print " === Serial === " t1 = time.time() download("http://www.stackless.com/wiki/Tasklets") download("http://www.stackless.com/wiki/Channels") t2 = time.time() print " --->", t2-t1 print " === Parallel === " t1 = time.time() stackless.tasklet(download)("http://www.stackless.com/wiki/Tasklets") stackless.tasklet(download)("http://www.stackless.com/wiki/Channels") stackless.run() t2 = time.time() print " --->", t2-t1 -->8--------------------------------------------------------------8<-- Here are a couple of runs to show that the *same* code works in both serial and parallel modes, and that parallel really is faster (hence I'm not bandwidth limited) % spython asynch_fetch.py === Serial === Downloaded http://www.stackless.com/wiki/Tasklets in 2.6 seconds Downloaded http://www.stackless.com/wiki/Channels in 2.7 seconds ---> 5.34717988968 === Parallel === Downloaded http://www.stackless.com/wiki/Channels in 4.0 seconds Downloaded http://www.stackless.com/wiki/Tasklets in 5.4 seconds ---> 5.43875193596 % spython asynch_fetch.py === Serial === Downloaded http://www.stackless.com/wiki/Tasklets in 2.6 seconds Downloaded http://www.stackless.com/wiki/Channels in 2.7 seconds ---> 5.32963705063 === Parallel === Downloaded http://www.stackless.com/wiki/Channels in 2.2 seconds Downloaded http://www.stackless.com/wiki/Tasklets in 2.7 seconds ---> 2.71087312698
participants (1)
-
richard.m.tew@gmail.com