Embedding and threads ?

Martin v. Löwis loewis at informatik.hu-berlin.de
Wed May 29 09:38:21 EDT 2002


Bo Lorentsen <bl at netgroup.dk> writes:

> Now is this possible ? 

Yes, but you need to make additional modifications.

> Will each python code run separatly, in issolated environments ?

No. Even if you manage to separate the interpreters, you will still
get a single copy of the global variables.

> Will it coredump ?

Most likely. You need to acquire the Global Interpreter Lock before
executing each piece of code.

> Can I control what the python code is allowed to import, and where
> stdout/err/in is directed ?

Certainly. To restrict imports, I recommend to compile and execute
code fragments inside an rexec sandbox. Alternatively, since you are
embedding Python, you could also disable dynamic loading of modules,
and provide a fixed modules table in your executable.

To control stdout/err/in, you need to assign to
sys.stdout/err/in. This won't catch direct references to stdout from C
code, which should be rare - if you ever trigger one of those in the
Python core, you should report that as a bug.

> Are there any other way of controlling the execution environment of
> earch thread, like getting a kind of execution context thingy ?

This is what you need to do: each thread must maintain a Python thread
state, and the thread must hold the GIL.

Regards,
Martin




More information about the Python-list mailing list