Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to reinitialise an embedded Python interpreter?
    primarykey
    data
    text
    <p>I'm working on embedding Python in our test suite application. The purpose is to use Python to run several tests scripts to collect data and make a report of tests. Multiple test scripts for one test run can create global variables and functions that can be used in the next script. </p> <p>The application also provides extension modules that are imported in the embedded interpreter, and are used to exchange some data with the application.</p> <p>But the user can also make multiple test runs. I don't want to share those globals, imports and the exchanged data between multiple test runs. I have to be sure I restart in a genuine state to control the test environment and get the same results.</p> <p>How should I reinitialise the interpreter?</p> <p>I used Py_Initialize() and Py_Finalize(), but get an exception on the second run when initialising a second time the extension modules I provide to the interpreter. And the documentation <a href="http://docs.python.org/c-api/init.html#Py_Finalize">warns against using it more than once</a>.</p> <p>Using <a href="http://docs.python.org/c-api/init.html#sub-interpreter-support">sub-interpreters</a> seems to have the same caveats with extension modules initialization.</p> <p>I suspect that I'm doing something wrong with the initialisation of my extension modules, but I fear that the same problem happens with 3rd party extension modules.</p> <p>Maybe it's possible to get it to work by launching the interpreter in it's own process, so as to be sure that all the memory is released.</p> <p>By the way, I'm using boost-python for it, that also warns AGAINST using Py_Finalize!</p> <p>Any suggestion?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload