473,238 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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_NewInterpreter() 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.waitIteration() ), 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 2143
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.com (bmatt) wrote in message news:<ef*************************@posting.google.c om>...
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_NewInterpreter() 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.waitIteration() ), 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.com> wrote in message
news:ef*************************@posting.google.co m...
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
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...
7
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...
5
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...
0
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...
3
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...
35
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...
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...
3
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...
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: ...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.