multiple interpreter sessions

Helge Hess helge.hess at mdlink.de
Mon Apr 3 11:48:55 CEST 2000


Tim Peters wrote:
> [Helge Hess]
> > I would like to have separate Python runtimes in a single server, so
> > that they don't affect each other (eg for security and state reasons).
> > ...
> 
> See the description of Py_NewInterpreter() in the "Initialization,
> Finalization, and Threads" section of the Python/C API manual.  You can
> create sub-interpreters from a C extension this way, but there's no
> Python-level interface to this at present.  Haven't used it myself, and,
> indeed, have yet to see any use of it.

Do you have another suggestion on how to implement 'multi-user Python'
in a single process ? I have some kind of application server which is
written mostly in C and I want to let the user write extensions in
Python. Since multiple users (and scripts) can be active in one process
I need to separate them from each other. I can't see how I can
accomplish that in another way if the user chooses to import something
(since the import [at least the module init] is global).

Besides that Py_NewInterpreter() seems to be what I want. I'm somewhat
confused that I get back a thread-state, do I switch between different
interpreters by doing some kind of manual context switch of Python
threads [that is, by calling save and restore thread] ?

thanks
  Helge



More information about the Python-list mailing list