MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / SpawnPython

Function SpawnPython

solve/ngsolve.cpp:65–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64
65void SpawnPython ()
66{
67 if(pythread_id != mainthread_id)
68 {
69 cout << "Python thread already running!" << endl;
70 }
71 else
72 {
73 std::thread([]()
74 {
75 AcquireGIL gil_lock;
76 try{
77 Ng_SetRunning (1);
78 pythread_id = std::this_thread::get_id();
79 pyenv.exec(
80 "import ngsolve.__console;"
81 "_vars2 = globals();"
82 "_vars2.update(locals());"
83 "ngsolve.__console.startConsole(_vars2)"
84 );
85 Ng_SetRunning (0);
86 }
87 catch (py::error_already_set const &) {
88 PyErr_Print();
89 }
90 cout << "Python shell finished." << endl;
91
92 pythread_id = mainthread_id;
93
94 }).detach();
95 /*
96 cout << IM(1)
97 << "ngs-python objects are available in ngstd, bla, ...\n"
98 << "to import the whole bunch of objets enter\n\n"
99 << "from ngsolve.ngstd import *\n"
100 << "from ngsolve.bla import *\n"
101 << "from ngsolve.fem import *\n"
102 << "from ngsolve.la import *\n"
103 << "from ngsolve.comp import *\n"
104 << "from ngsolve.solve import *\n"
105 // << "from ngsolve.ngmpi import *\n"
106 << "dir()\n"
107 << endl << endl;
108 */
109#ifdef PARALLEL
110 cout << IM(1) << "To start the mpi shell call" << endl << "MpiShell()" << endl << endl;
111#endif
112 }
113}
114
115#endif
116

Callers 1

NGS_PythonShellFunction · 0.85

Calls 2

IMClass · 0.85
execMethod · 0.80

Tested by

no test coverage detected