[Stackless] An idea for making Stackless more naturally usable

Richard Tew richard.m.tew at gmail.com
Mon Sep 4 13:42:00 CEST 2006


Hi,

I have been talking with Andrew Dalke about his experiences with
Stackless and he did something simple which just hadn't occurred
to me.  He was using my replacement socket module for Stackless
which does the IO asynchronously though the 'asyncore' module
blocking calling tasklets on channels in the meantime.

You can see it here, if you haven't already:
http://www.stackless.com/wiki/Examples

But what he was doing with it, was to install it as the socket module
you get when you do "import socket" anywhere, which means that
any standard modules (like 'urllib' in this case) would just work in
a Stackless compatible way because they transparently used the
replacement version.

In case it is not clear what I mean by a "Stackless compatible way",
I will explain it in this paragraph, so skip it if you already understand.
Blocking synchronous operations, like file IO or networking calls,
block the whole interpreter.  By doing these operations asyncronously
or farming out the blocking to a thread, we can in the meantime
block the calling tasklet on a channel until we have the result,
which we can then send to it through the channel letting it continue
where it was.  And because the interpreter carries on while threads
or asynchronous operations do the work the interpreter would
otherwise block for, can continue to be scheduled.

Now, the natural next step from this is to replace all blocking calls
in the builtins, standard lib or whatever with similar support.  Like the
file IO, so that when you import Stackless and choose to install
this replacement (perhaps through monkey patching), then all the
resources the Python interpreter provides just works, never blocking
the scheduler.

Andrew's suggestion was to have something like this:

  import stackless
  stackless.monkeypatch()

Where this would hook-in and override all the necessary things.

It will however, be a lot of work.

Any thoughts, questions or comments?
Richard.

_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list