473,761 Members | 6,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple Interpreters In a Single Thread

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 predefined
functions can be resolved using that module name?

If it is necessary then how is this accomplished? I have tried using
Py_NewInterpret er() but have been getting a strange crash (invalid
thread state).

Another concern I have is that I would like to be able to support
scripts defining their own application loop like functions. These
functions will need to be able to pause and wait for the next
application loop iteration before continuing. So...is there a way to
stop the interpreter ( via a call to an application defined function
like system.waitIter ation() ), save the state of the interpreter and
continue processing when the application says it is ready?

I know these are kind of high level and vague questions but I am just
in the proof of concept and design phase and need to make sure some of
my ideas are feasible. Any information would be appreciated.

Thanks
Jul 18 '05 #1
2 2170
I wanted to follow up on my post and let everyone how I decided to
tackle this problem. If you see any inherent problems with my solution
or know of a better way to handle it then let me know.

I decided to run each script in a separate thread but force them to
run synchronously. This may seem like overkill but it allows me to use
separate python interpreters (secondary concern) and facilitates the
scripts ability to relinquish control back to the main application
thread so that it can wait a single program loop iteration or wait a
specific amount of time before continuing or wait for some other
defined event.

bs****@gmail.co m (bmatt) wrote in message news:<ef******* *************** ***@posting.goo gle.com>...
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 predefined
functions can be resolved using that module name?

If it is necessary then how is this accomplished? I have tried using
Py_NewInterpret er() but have been getting a strange crash (invalid
thread state).

Another concern I have is that I would like to be able to support
scripts defining their own application loop like functions. These
functions will need to be able to pause and wait for the next
application loop iteration before continuing. So...is there a way to
stop the interpreter ( via a call to an application defined function
like system.waitIter ation() ), save the state of the interpreter and
continue processing when the application says it is ready?

I know these are kind of high level and vague questions but I am just
in the proof of concept and design phase and need to make sure some of
my ideas are feasible. Any information would be appreciated.

Thanks

Jul 18 '05 #2

"bmatt" <bs****@gmail.c om> wrote in message
news:ef******** *************** **@posting.goog le.com...
I am trying to support multiple interpreter instances within a single
main application thread.
I think it sounds tricky and doomed to endless debugging - given that one
does not really have full control over the interpreter, not many people "go
there" and therefore there may lurk undocumented implementation & machine
detail that change suddently ...
Any information would be appreciated.


I *guess* that what you want to do is to be able to attach/detach
functionality to an application so that 'the user' can build/customise his
own custom tool from a set of available building-blocks and some runtime
configuration tool?

If you base your framework on Pyro and design a protocol for registration,
location and inter-connection of Services, I think your life might be
simpler; With Pyro your independent Python Thread will be in separate
applications, but the Pyro interface makes all objects appear local to the
application using them. I like it.

http://pyro.sourceforge.net/
Jul 18 '05 #3

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

Similar topics

1
2153
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 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:
7
11215
by: Guyon Morée | last post by:
If I have multiple threads reading from the same file, would that be a problem? if yes, how would I solve it? Let's say I want to take it a step further and start writing to 1 file form multiple threads, how would I solve that? thanx,
5
4621
by: Tommy | last post by:
Just recently, I happened came across one .net multithreading book saying that multithread programs might get differential in stability when running on single CPU machine compared to a multi-CPU one.The book also recommands a way in .NET to run specific thread on specific CPU. Now I am facing a new project which is going to be deployed to either a single or a multiple CPU machine. My problem is: can .NET 'automatically' detect CPU status...
0
1098
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
8450
by: ian_jacobsen | last post by:
First let me start by saying that this problem is not consistently reproducible. I have a windows service that creates reports for a group of entities. This service can process multiple groups at a single time, where each group is running in a separate thread. I have noticed mixed behavior when running multiple groups at one time (in separate threads). I have received the following two messages logged as errors. - A Crystal Reports...
35
9363
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from 500000 to 3200000 of a file whose size is say 20MB... how do i request a download which starts directly at 500000th byte... thank u cheers
0
1565
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
9179
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
12579
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
9336
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,...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
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
8770
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
7327
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
5215
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...
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.