[Stackless] An idea for making Stackless more naturally usable
Andrew Dalke
dalke at dalkescientific.com
Tue Sep 5 01:33:09 CEST 2006
Hi all,
I worked some this evening improving Richard's stacklesssocket
module. See the SVN commit logs in the sandbox for details.
Here's an example of using the monkey-patched module, to show what
"more naturally" might mean.
======
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
======
Same code for serial and parallel versions. Here's example
output clearly showing that they are serial and parallel. (Don't
ask me why the stacklesssocket works correctly even when I
haven't done a stackless.run() -- I'm still new at stackless.)
% spython async_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 async_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
Andrew
dalke at dalkescientific.com
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list