Task Isolation in Python (was Re: How do you develop in Python?)

Glyph Lefkowitz glyph at twistedmatrix.com
Mon Jun 11 00:37:29 CEST 2001

On Sun, 10 Jun 2001, Nick Perkins wrote:

> I want an IDE to provide at least the following:
> 1. Each run takes place in a fresh, clean environment.
> 2. The IDE stays responsive while a program is run.
> 3. The IDE can kill a running program.

One idea which I've been kicking around (and finally even started a little
implementation of last night) is a Python interpreter in Python.  I
believe that the existing compiler is relatively robust (at least, I
haven't been able to generate any source code that can crash or hang it
yet), but the bytecode interpreter can't isolate tasks, which makes it
impossible to kill a process or even slow it down to see what it's doing.  
Stackless seems like it might make this possible, but it's still using
essentially the same partially-recursive interpreter. I'm also interested
in running completely untrusted code from python bytecode.  However, the
tricky parts are in making sure that this meta-interpreter isn't
recursive.  (In particular, I am getting stuck on operator overloading,
since it's possible to implement __getattr__...)

Some advantages that this approach would have:

 * .pyc bytecode interpreter for Jython.
 * untrusted code execution
 * resource control
 * mobile code
 * defined API for communication between isolated tasks
 * ability to run "blocking" code without threads in a singlethreaded app
 * educational value; easier to read than ceval.c
 * task-scheduling in python without continuations
 * IDEs could safely execute/debug development code w/o a separate process
 * python code would run 2 orders of magnitude slower, making it even more

Has anyone attempted such a thing before, or have any advice to give me?

Also, is it easy/possible to crash the "marshal" module with bad data?

                      ______      __   __  _____  _     _
                     |  ____ |      \_/   |_____] |_____|
                     |_____| |_____  |    |       |     |
                     @ t w i s t e d m a t r i x  . c o m

More information about the Python-list mailing list