Creating an execution environment

Juan M. Casillas juanm.casillas at eresmas.com
Tue Jun 25 04:13:39 EDT 2002


Hello to all !

      First of all, sorry by this long, boring mail :)

      I'm trying to do a simple execution environment with python
      embedded into a C program. I want to have some "environments"
      each one with its own data, functions, classes, and so on. But
      I don't know how to create separate environments with the same
      parser. I try to archieve that with multiple modules, but this
      is not the right focus for this problem, because the modules
      can access the code from another modules.

      It's posible to have multiple environments with a single python
      interpreter ? its posible to have multiple interpreters in a 
      C program ? Also, I want to load chunks of code for multiple
      files, and then add the symbols to the right environment...

      e.g.

      I want to create two separate execution environments, env1 and
      env2. Also, the code from preload.py should be included in the
      two environments but not as module, just as if the code was
      defined in the same file.

      -->file preload.py<--
      class PG:
	    name = ""
	    def __init__(self,name):
		self.name = name
	    def getName(self):
		return(self.name)

      -->file env1.py<--

      def env1_func(arg1):
	  return(arg1*3)

      pg = PG('hello')
		

      -->file env2.py<--	     
      
      def env2_func():
	  return('hello from env2')

      thing = PG('thing')
            
	

      So I want to call environment's functions or object methods
      from my C code, having the two environments isolated. Can be
      this done with python ? How can I merge the code from the
      files in the same execution environment ?

      I do some tests, but the unique way to have some similar is
      creating one module for each environment, and importing them
      from the C code. Any ideas ?


Thanks in advance,

--
Juan M. Casillas
assman at eresmas.com	












More information about the Python-list mailing list