Hope this is the right mailing list, please complain if not ;)
I'm currently experimenting with the integration of Python (2.6) scripts
into my application, and am using the following script for testing:
*import* threading, time
t = threading.Thread(target = handler)
And in C++, it's this code:
*if*(!Py_IsInitialized()) *throw* std::exception();
PyObject *module = PyImport_AddModule("__main__");
PyObject *dict = PyModule_GetDict(module);
strcpy(script, "import threading, time\n"
"t = threading.Thread(target = handler)\n"
PyObject *obj = PyRun_String(script, Py_file_input, dict, dict);
When executing, the output is
as opposed to the expected
It seems to me that when the main execution path (after t.start())
finishes, the other thread (called t) is canceled?! Adding t.join() to
the end of the script gives the expected output, but isn't it possible
to let PyRun_xxx wait for all remaining threads to end? I know the
Python interpreter does this, but I didn't get much information from its
source code (it seems to run scripts with the runpy module).