Re: Fwd: twin interpreters in safe-tcl, but in Python?
Sat, 18 Jun 1994 12:01:18 +0200

> OK, here's a fun one. Can this be done in Python?
> its library calls is
> Tcl_CreateInterp();
> which creates a new instance of a TCL interpreter context.
> In Safe-Tcl, two such contexts are created. The untrusted
> context has the nasty commands removed from its dictionary
> of commands, and a limited set of new primitives added to
> its command set. The other context has all the standard
> TCL (and TK) commands, plus some additional commands to
> extern control over the untrusted interpreter context.
> Each context also has its own set of TCL variables that
> are completely disjoint from each other (unless you create
> a primitive that ties TCL variables from different contexts
> together).

No, this can't easily be done in current Python. I've had more
requests for totally independent Python interpreters along the lines
of Tcl, but in most cases what people really need was something much
simpler, e.g. separate modules or separate "globals" dictionaries for
code executed by exec, eval() or execfile(). The idea expressed here
looks quite elegant -- on the other hand "taintperl" seems to
implement a similar functionality without multiple interpreters.

It would not be very difficult to change Python to allow multiple
independent interpreter contexts, but it won't be trivial either --
there are some global variables here and there (especially the
current exception and the current execution frame) and some built-in
modules may not expect to be initialized more than once (these also
tend to use global variables -- e.g. sys).

--Guido van Rossum, CWI, Amsterdam <>
URL: <>