Embedding and threads ?

Bo Lorentsen bl at netgroup.dk
Fri May 31 06:01:06 EDT 2002


On Fri, 2002-05-31 at 10:51, Martin v. Löwis wrote:
 
> 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
function.

> Most certainly they can. They surely do use physical operating system
> threads. However, many of the threads may be blocked waiting for the
> GIL.
One day I may understand this, but until then I hope you bear with me
:-) So, besides the ThreatStates, what else does GIL protect ? 

> You can run Python in parallel with a C++ thread just fine. If two
> threads simultaneously want to execute Python code, one of the threads
> will block on the GIL.
Arhh, so Python can execute in a MT environment, but only one
interpreter at a time, the rest is pseudo MT ?

> > But I will not be able to have two Python interpreter states running in
> > true parallel ?
> 
> With a single processor, you cannot run *any* true threads in true
> parallel. On a multiprocessor system, yes, you currently cannot run
> two Python threads at the very same time.
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.

/BL






More information about the Python-list mailing list