473,624 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple interpreters in a single process

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 interpreter does not influence the
other. In essence, the interpreter can be used in different modules of a
single application. It would be nice to isolate them.

There are two possibilities:

1. The interpreters need to run in paraller (from different threads of
the master application). Definitely, separate interpreters are needed.

2. Different modules use a single Python interpreter in non-overlapping
times. At least the possibility to clean up the interpreter is needed.

Is this problem easy to solve? Or maybe are there alternative approaches
(switchable dictionaries, etc.)?

Thank you very much,

--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/

Jul 18 '05 #1
1 2149
In article <bt**********@a tlantis.news.tp i.pl>,
Maciej Sobczak <no*****@no.spa m.com> wrote:

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 interpreter does not influence the
other. In essence, the interpreter can be used in different modules of a
single application. It would be nice to isolate them.


Unfortunately, it's not really possible to do that. The problem is that
Python is designed to interface to C libraries, many of which use global
static variables. So Python doesn't really try to allow isolated Python
instances. Your best bet if you need true isolation is to run multiple
processes.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

A: No.
Q: Is top-posting okay?
Jul 18 '05 #2

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

Similar topics

2
3399
by: Michael Schmitt | last post by:
Hello. What is the usual way for running functions in parallel on a multiple-processor machine. Actually I want to run a single computationally expensive function with different parameter sets. Running the functions in different threads doesn't seem to work, because of the global interpreter lock. Would it help to fork processes, which run the single function with a given parameter set? Is there any simple way, how this forked worker...
2
2165
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 python scripts via a well defined interface (i.e. The onCreate script will be called when the object is created). So...Is it necessary to use multiple interpreters since each script I import will be given its own module name and therefore the...
9
23067
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated to a pool. If I assign only one application to a applicaton pool and have multiple worker processes assigned to that pool. Will my application be processed by many worker processes?
0
1088
by: gabriel.becedillas | last post by:
Hi, At the company I work for we've embedded Python 2.4.1 in a C++ application. We execute multiple scripts concurrenlty, each one in its own interpreter (created using Py_NewInterpreter()). We are sharing a certain instance between interpreters because its to expensive to instantiate that class every time an interpreter is created. The class is instantiated in the main interpreter (that is always alive) and every time a new interpreter...
3
2575
by: Michel | last post by:
Hi, I wrote an app in .Net and I whant only 1 instance of this app open for the user; the user open my app, do some works and try to open another instance of my app, I whant to show a message to user to inform him that only one instance is permit and then close the second instance after that. I am able to do this when the user run the application on his PC whit this : Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName) ...
4
3767
by: Diffident | last post by:
Hello All, IIS 6.0 - I have an application which resides in its own application pool. Does anyone know if we can create multiple application pools for the same application? If we can create multiple application pools to serve a single application's request will it improve the performance? Thanks for your suggestions!!
0
1560
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 execute a run script function. The code is as follows: RunScript(char *pScriptName,char *pFuncName,...) { PyEval_AcquireLock()
3
9156
by: Marcin Kalicinski | last post by:
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
7
12538
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: C++ main thread 1 Py_Initialize() thread 2 Py_Initialize()
0
8231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8168
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8330
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7153
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6107
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4075
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4167
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.