472,982 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 software developers and data experts.

Multiple python interpreters within the same process

How do I use multiple Python interpreters within the same process?

I know there's a function Py_NewInterpreter. However, how do I use functions
like Py_RunString etc. with it? They don't take any arguments that would
tell on which interpreter to run the string...?

Marcin
Jun 9 '07 #1
3 9010
On Jun 9, 5:00 pm, "Marcin Kalicinski" <kal...@poczta.onet.plwrote:
How do I use multiple Python interpreters within the same process?

I know there's a function Py_NewInterpreter. However, how do I use functions
like Py_RunString etc. with it? They don't take any arguments that would
tell on which interpreter to run the string...?

Marcin
You may want to look at the code module http://docs.python.org/lib/module-code.html

André

Jun 9 '07 #2
André wrote:
On Jun 9, 5:00 pm, "Marcin Kalicinski" <kal...@poczta.onet.plwrote:
>How do I use multiple Python interpreters within the same process?

I know there's a function Py_NewInterpreter. However, how do I use functions
like Py_RunString etc. with it? They don't take any arguments that would
tell on which interpreter to run the string...?

Marcin

You may want to look at the code module http://docs.python.org/lib/module-code.html
That's completely unrelated.

To answer Marcin's question, from what I understand, running multiple
Python interpreters is not supported. There are various issues with
object sharing and refcounts, etc., and are unlikely to be fixed soon if
ever.

- Josiah
Jun 9 '07 #3
On Jun 10, 9:07 am, Josiah Carlson <josiah.carl...@sbcglobal.net>
wrote:
André wrote:
On Jun 9, 5:00 pm, "Marcin Kalicinski" <kal...@poczta.onet.plwrote:
How do I use multiple Python interpreters within the same process?
I know there's a function Py_NewInterpreter. However, how do I use functions
like Py_RunString etc. with it? They don't take any arguments that would
tell on which interpreter to run the string...?
Marcin
You may want to look at the code modulehttp://docs.python.org/lib/module-code.html

That's completely unrelated.

To answer Marcin's question, from what I understand, running multiple
Python interpreters is not supported. There are various issues with
object sharing and refcounts, etc., and are unlikely to be fixed soon if
ever.
I really don't know why people keep propagating this myth that you
can't run multiple Python interpreters. :-(

The Python C API has supported multiple Python interpreter instances
within a single process for a long time. If you write your C program
correctly there isn't a problem. The only real limitation is that
different Python interpreter instances can't use different versions of
a C extension module as they when loaded are shared across all Python
interpreter instances.

C extension modules can also cause other problems as well, but this
isn't the fault of Python but of the module writers. Specifically, if
a C extension module is written to only use the simplified API for GIL
locking it can only be used with the first Python interpreter instance
created. If they use the wider GIL locking API properly then there is
no problem with using it in other Python interpreter instances.
Another issue although one which you aren't likely to come across
unless you are doing really tricky stuff, is where a C extension
module was written so as to assume that once it is loaded into a
Python interpreter instance, that that interpreter will not be
destroyed. From what I have seen Pyrex generated C extension modules
possibly have this latter problem and will cause a process to crash if
a Python interpreter instance is destroyed and then a new one created
in its place.

As proof that all this stuff can work, have a look at mod_python and
mod_wsgi. Both make use of multiple Python interpreter instances in a
single process. The mod_wsgi documentation even points out the above
problems with C extension modules in latter sections of:

http://code.google.com/p/modwsgi/wiki/ApplicationIssues

Graham

Jun 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maciej Sobczak | last post by:
Hi, I'm interested in embedding the Python interpreter in a C++ application. What I miss is the possibility to create many different interpreters, so that the stuff that is running in one...
4
by: Paul Miller | last post by:
Some background first - we have some software that embeds a Python interpreter into a host application. Scripts are loaded dynamically and used. But we want to support the ability to edit scripts...
2
by: bmatt | last post by:
I am trying to support multiple interpreter instances within a single main application thread. The reason I would like separate interpreters is because objects in my system can be extended with...
47
by: Pierre Barbier de Reuille | last post by:
Please, note that I am entirely open for every points on this proposal (which I do not dare yet to call PEP). Abstract ======== This proposal suggests to add symbols into Python. Symbols...
20
by: Ramdas | last post by:
How do I add users using Python scripts on a Linux machine? Someone has a script?
0
by: has | last post by:
Hi all, need a little bit of advice on dynamically binding an embedded Python interpreter. First, the code for anyone that wants a look: ...
5
by: Adam Atlas | last post by:
Does anyone know if it would be possible to create a CPython extension -- or use the ctypes module -- to access Python's own embedding API (http://docs.python.org/api/initialization.html &c.)?...
0
by: vishnu | last post by:
Hello All, I have embedded python 2.5 in to my C application. As we need the python scripts to run in multi threaded environment I have used Py_NewInterpreter() and Py_EndInterpreter each time I...
7
by: skip | last post by:
This question was posed to me today. Given a C/C++ program we can clearly embed a Python interpreter in it. Is it possible to fire up multiple interpreters in multiple threads? For example: ...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.