1 %extend SoWin {
mainLoop(void)2   static void mainLoop(void) {
3     PyRun_SimpleString("import sys");
4     PyObject *d = PyModule_GetDict(PyImport_AddModule("__main__"));
5     PyObject *result = PyRun_String("sys.argv[0]", Py_eval_input, d, d);
6     /* if we are calling from within an interactive python interpreter
7      * session spawn a new InteractiveLoop in a new thread. determined
8      * by sys.argv[0] == ''. otherwise proceed as usual.
9      */
10 #ifdef PY_2
11     if (!strcmp(PyString_AsString(result), "")){
12 #else
13     if (!strcmp(PyBytes_AsString(result), "")){
14 #endif
15       cc_thread *py_thread = cc_thread_construct(Pivy_PythonInteractiveLoop, NULL);
16       SoWin::mainLoop();
17       void *retval = NULL;
18       cc_thread_join(py_thread, &retval);
19       cc_thread_destruct(py_thread);
20       Py_Exit(0);
21     } else {
22       SoWin::mainLoop();
23     }
24   }
25 }
26