Embedding and threads ?
Martin v. Löwis
loewis at informatik.hu-berlin.de
Sun Jun 2 11:35:24 CEST 2002
Bo Lorentsen <bl at netgroup.dk> writes:
> > I lost track. How do you set the builtins, and why do you have to?
> Before calling "PyEval_EvalCode", I have to make this call, or I was not
> even able to use the build in functions like "range" !
> PyDict_SetItemString( pDict, "__builtins__", PyEval_GetBuiltins());
> pDict is both the local and the global dict. for the PyEval_EvalCode
I see. This is necessary indeed. The builtins are normally inherited
from some context when doing "exec" or "eval" at the Python level; on
the C API, no such inheritance happens automatically.
> One day I may understand this, but until then I hope you bear with me
> :-) So, besides the ThreatStates, what else does GIL protect ?
Nearly everything in Python
- changing and accessing dictionaries
- changing and accessing lists
- writing to files
- allocating memory (atleast with pymalloc)
etc. None of these operations is thread-safe per se; it is only the
GIL that prevents breakage.
> Arhh, so Python can execute in a MT environment, but only one
> interpreter at a time, the rest is pseudo MT ?
I don't think I understand this question. As I said before, restrict
yourself to "one interpreter" (in the sense of PyInterpreterState*).
This is the normal case even in the presence of threads.
I don't know what pseudo MT is (in what sense is it pseudo?). It
certainly has multiple concurrent threads.
> Now, this makes more sense ! Do you know if there is any plans to make
> Python more flexible for (real) MT processing in the future ? When
> looking into the code, it looks like someone have tried to modulize it
> so that it could be real MT in the future, at least as far as the core
> language goes.
For most people, it is "real" MT today, since they have only one
processor in their computers, anyway.
To make it "more real", you would have to introduce what is known as
"free threading". People have tried this (ask Google) and found that
it slows down the interpreter significantly.
More information about the Python-list