Multiple Interpreters In a Single Thread

B

bmatt

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
 
B

bmatt

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.
 
F

Frithiof Andreas Jensen

bmatt said:
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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top