[Stackless] An idea for making Stackless more naturally usable
Andrew Dalke
dalke at dalkescientific.com
Tue Sep 5 02:15:22 CEST 2006
Richard:
> Andrew's suggestion was to have something like this:
>
> import stackless
> stackless.monkeypatch()
>
> Where this would hook-in and override all the necessary things.
Max Noel:
> I think it'd be worth a try. The great unknown here, is how the
> standard library will behave once this change is implemented.
My hope would be to minimize those differences. Some are rather
hard to fix though, like waitpid. Spawn off a system thread for
each one? Or emulate by adding a NOBLOCK along with some sort
of sleep(0.1) or so?
BTW, does Stackless work well with OS threads? What caveats
are there? The readme (in Stackless/readme.txt, dated
"A small update as of 2006-03-01" says "supporting both
cooperative switching and stack switching, with the addition
of partially complete support for real OS threads as a tasklet."
but that's all I could find.
One thought I had is to monkey-patch plus use a threading.local
so
_config = threading.local()
def register_thread_for_stackless():
_config.using_stackless = True
_config.emulation_timeout = 0.1
def socket(*args):
if getattr(_config, "using_stackless"):
return stacklesssocket.socket(*args)
else:
return stdsocket.socket(*args)
Thus an OS thread can run with near-native performance and
with no chance of emulation errors.
Max:
> Still, it's worth a try. It could also be interesting to provide an
> asynchronous reimplementation of parts of the stdlib (an AsyncFile
> class, perhaps?) as a proof of concept, to study some of the
> possible side effects.
Try out stacklesssocket (from svn) - it's good enough
to support urllib ... though there is a bug when an exception
occurs which I haven't tracked down yet. Don't have a reproducible.
According to the notes in asyncore
# Asynchronous File I/O:
#
# After a little research (reading man pages on various unixen, and
# digging through the linux kernel), I've determined that select()
# isn't meant for doing asynchronous file i/o.
# Heartening, though - reading linux/mm/filemap.c shows that linux
# supports asynchronous read-ahead. So _MOST_ of the time, the data
# will be sitting in memory for us already when we go to read it.
#
# What other OS's (besides NT) support async file i/o? [VMS?]
#
# Regardless, this is useful for pipes, and stdin/stdout...
which makes me happy because one of the things I want to stackless-ify
is subprocess, which uses pipes and hence should work with asyncore.
Otherwise I think the only solution is an OS thread. Hmmm, or replace
open(filename) with
some_async_dispatcher(os.popen("cat " + filename))
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