This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author theDarkBrainer
Recipients ned.deily, theDarkBrainer
Date 2013-03-13.14:18:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1363184317.83.0.376739436894.issue17408@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2013-03-13 14:18:37theDarkBrainersetrecipients: + theDarkBrainer, ned.deily
2013-03-13 14:18:37theDarkBrainersetmessageid: <1363184317.83.0.376739436894.issue17408@psf.upfronthosting.co.za>
2013-03-13 14:18:37theDarkBrainerlinkissue17408 messages
2013-03-13 14:18:37theDarkBrainercreate