By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

Multiple Interpreters In a Single Thread

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.