Vlad added the comment:

I'm trying to embed the python 3.3 engine for an app that need to run custom 
scripts in python. Since the scripts might be completely different, and 
sometimes user provided, I am trying to make each execution isolated and there 
is not need to preserve any data between execution of the different scripts.

So, my solution is to wrap each execution between 'Py_Initialize' and 
'Py_Finalize'. It looks something like that:

  void ExecuteScript(const char* script)
  {
    Py_Initialize();
  
    PyRun_SimpleString( script );
  
    Py_Finalize();
  }

However, this fails for a particular python script the second time a script is 
executed with:

  done!
  Traceback (most recent call last):
    File "<string>", line 8, in <module>
    File "\Python33Test\Output\Debug\Python33\Lib\copy.py", line 89, in copy
      rv = reductor(2)
  TypeError: attribute of type 'NoneType' is not callable


The python script looks like this:

  class Data:
      value1 = 'hello'
      value2 = 0
  
  import copy
  
  d = Data()
  dd = copy.copy( d )
  print ( 'done!' )

As you can see, the first time around the script was executed the 'done!' was 
printed out. But the second time it rises an exception inside the copy function.

It looks like the python engine was left in some weird state after the first 
initialize-finalize. Note, this is python 3.3.

Also, it is very interesting to note that Python 2.7 and Python 3.2 did not 
have this problem.

I guess there might be other examples that could reveal better what's going, 
but i haven't had the time to find yet.

I also put a copy of the project containing flag to switch between Python 3 and 
Python 2.7 (the file is 31 MB): 
https://docs.google.com/file/d/0B86-G0mwwxZvbWRldTd5b2NNMWM/edit?usp=sharing

Thanks, Vlad

----------
Added file: http://bugs.python.org/file29398/Python33Test.zip

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17408>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to