Multiple Interpreters In a Single Thread

bmatt bsmatt at gmail.com
Mon Sep 27 20:43:55 CEST 2004


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.



bsmatt at gmail.com (bmatt) wrote in message news:<efd29696.0409230652.8c6f748 at posting.google.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_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



More information about the Python-list mailing list