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 <>
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)
    PyRun_SimpleString( script );

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

  Traceback (most recent call last):
    File "<string>", line 8, in <module>
    File "\Python33Test\Output\Debug\Python33\Lib\", 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):

Thanks, Vlad
Date User Action Args
2013-03-13 14:18:37theDarkBrainersetrecipients: + theDarkBrainer, ned.deily
2013-03-13 14:18:37theDarkBrainersetmessageid: <>
2013-03-13 14:18:37theDarkBrainerlinkissue17408 messages
2013-03-13 14:18:37theDarkBrainercreate