[Pythonmac-SIG] Re: Python Reentrant?

Russell E Owen owen@astro.washington.edu
Mon, 28 Jan 2002 08:17:08 -0800


Jon Bradley wrote:

>Does anyone know forsure whether or not Python 2.2 is reentrant?...We're embedding Python and will want to be able to have more than one thread
>evaluating a Python expression at one time.

I'm not expert on this, but I hope others will correct any errors. By the way, you'd probably get a better response on a more general Python discussion list or on the news group.

I don't believe Python is reentrant, based on:
- Only one copy of the Python interpreter can be running at a given time (at least on certain platforms)
- Python has a global interpreter lock.

Your simplest solution would probably be to write your application using Python's own threads. If you need to have external code running parts of your application, build Python extensions (not that hard to do, though you will have to be careful with the Python interpreter lock).

As an alternative, it is conceivable you could get various threads to call Python in a way that obtains the interpreter lock. I have no idea if this is possible or how to go about it.

-- Russell