Embedding and threads ?

Martin v. Löwis loewis at informatik.hu-berlin.de
Fri May 31 04:51:52 EDT 2002


Bo Lorentsen <bl at netgroup.dk> writes:

> But I have to set the builtins explictly

I lost track. How do you set the builtins, and why do you have to?

> > That is not the case. There is one thread state per thread. All but
> > one thread is blocked at any point in time (unless the other threads
> > execute unrelated C code); those threads have their thread state
> > preserved in a local variable at the point where they last executed
> > BEGIN_ALLOW_THREADS.
> So thread states can't run one in each fysical thread ! 

Most certainly they can. They surely do use physical operating system
threads. However, many of the threads may be blocked waiting for the
GIL.

> I think this is a bit confusing, as I don't see how to use Python in
> parallel from a threaded C/C++ application, or even how threads
> would work internally in Python itself, except if this is a light
> weight thread system.

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.

> 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.

Regards,
Martin





More information about the Python-list mailing list