1 // SUPERV GraphExecutor : contains classes that permit execution of graphs and particularly the execution automaton
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : DataFlowExecutor_PyDynInvoke.cxx
8 // Author : Jean Rahuel, CEA
17 #include "DataFlowExecutor_InNode.hxx"
18 #include "DataFlowExecutor_OutNode.hxx"
20 using namespace CORBA ;
22 //static PyObject * MyPyObjSignal = NULL ;
23 static PyObject * MyPyObjRef = NULL ;
24 static PyObject * MyPyObjIor = NULL ;
25 static PyObject * MyPyRunMethod = NULL ;
27 static PyMethodDef MethodPyRunMethod[] = {
28 { "RunMethod", PyRunMethod, METH_VARARGS },
32 bool GraphExecutor::InNode::InitPython() {
33 cdebug_in << "InitPython" << endl ;
35 Automaton()->PyLock() ;
36 // PyObject * Module = Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod ) ;
37 if ( !Automaton()->PyInitModule() ) {
38 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod ) ;
39 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
40 //_OutNode->SuperVisionContainer()->ActivatePythonExecution( "InitPyRunMethod" , MethodPyRunMethod ) ;
42 // PyObject * Dictionnary = PyModule_GetDict( Module ) ;
43 // InitPyDynInvokeError = PyErr_NewException( "InitPyDynInvokeError" , NULL , NULL ) ;
44 // PyDict_SetItemString( Dictionnary , InitPyDynInvokeError ) ;
45 cdebug << ThreadNo() << "Py_Initialized() " << endl ;
48 //JR : Python documentation says that there is no sense to set a handler of synchronous
49 // signals as SIGSEGV and SIGFPE !!!
50 if ( Automaton()->PyFunction( "PyObjSignal" ) == NULL ) {
52 aPyFunc = "import signal\n" ;
53 aPyFunc += "import InitPyRunMethod\n" ;
54 aPyFunc += "import sys\n" ;
55 aPyFunc += "import CORBA\n" ;
56 aPyFunc += "import omniORB\n" ;
57 aPyFunc += "def PySignalHandler( aSignal , aStackFrame ) :\n" ;
58 aPyFunc += " print 'PySignalHandler(aSignal =',aSignal,',aStackFrame= ',aStackFrame,')'\n" ;
59 aPyFunc += "InitPyRunMethod.RunMethod( PySignalHandler )\n" ;
60 aPyFunc += "PrevHandler = signal.signal( signal.SIGSEGV , PySignalHandler )\n" ;
61 aPyFunc += "print 'PyObjSignal PrevHandler of SIGSEGV :', PrevHandler\n" ;
62 aPyFunc += "print 'PyObjSignal actual handler of SIGSEGV :', signal.getsignal( signal.SIGSEGV )\n" ;
63 // if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
64 if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
65 cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
66 Automaton()->PyUnLock() ;
69 MyPyObjSignal = MyPyRunMethod ;
70 Automaton()->PyFunction( "PyObjSignal" , MyPyObjSignal ) ;
73 MyPyObjSignal = Automaton()->PyFunction( "PyObjSignal" ) ;
77 // PyObjRef convert an IOR (string) to an Python ObjectReference
78 if ( Automaton()->PyFunction( "PyObjRef" ) == NULL ) {
80 aPyFunc = "import InitPyRunMethod\n" ;
81 aPyFunc += "import sys\n" ;
82 aPyFunc += "import CORBA\n" ;
83 aPyFunc += "import omniORB\n" ;
84 aPyFunc += "def PyObjRef( IORObjStr ) :\n" ;
85 aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
86 aPyFunc += " objref = orb.string_to_object( IORObjStr )\n" ;
87 aPyFunc += " return objref\n" ;
88 aPyFunc += "InitPyRunMethod.RunMethod( PyObjRef )\n" ;
89 if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
90 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
91 //if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
92 cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
93 Automaton()->PyUnLock() ;
96 MyPyObjRef = MyPyRunMethod ;
97 Automaton()->PyFunction( "PyObjRef" , MyPyObjRef ) ;
100 MyPyObjRef = Automaton()->PyFunction( "PyObjRef" ) ;
103 // PyObjRef convert an Python ObjectReference to an IOR (string)
104 if ( Automaton()->PyFunction( "PyObjIor" ) == NULL ) {
106 aPyFunc = "import InitPyRunMethod\n" ;
107 aPyFunc += "import sys\n" ;
108 aPyFunc += "import CORBA\n" ;
109 aPyFunc += "import omniORB\n" ;
110 aPyFunc += "def PyObjIor( ObjRef ) :\n" ;
111 aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
112 aPyFunc += " objIor = orb.object_to_string( ObjRef )\n" ;
113 aPyFunc += " return objIor\n" ;
114 aPyFunc += "InitPyRunMethod.RunMethod( PyObjIor )\n" ;
115 if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
116 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
117 //if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
118 cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
119 Automaton()->PyUnLock() ;
122 MyPyObjIor = MyPyRunMethod ;
123 Automaton()->PyFunction( "PyObjIor" , MyPyObjIor ) ;
126 MyPyObjIor = Automaton()->PyFunction( "PyObjIor" ) ;
128 Automaton()->PyUnLock() ;
130 cdebug_out << "InitPython" << endl ;
135 void GraphExecutor::InNode::RemovePyDynInvoke( char * PyFuncName ) {
136 // Automaton()->PyLock() ; // Already done ...
137 if ( Automaton()->ErasePyFunction( PyFuncName ) ) {
138 cdebug << "InNode::RemovePyDynInvoke( " << PyFuncName << " ) success" << endl ;
141 cdebug << "InNode::RemovePyDynInvoke( " << PyFuncName << " ) ERROR failed" << endl ;
143 // Automaton()->PyUnLock() ;
146 PyObject * GraphExecutor::InNode::InitPyDynInvoke( char * PyFuncName ,
147 const SUPERV::ListOfStrings * aPythonFunction ,
152 PyObject * thePyRunMethod = NULL ;
154 cdebug_in << "InitPyDynInvoke '" << PyFuncName << "' length " << (*aPythonFunction).length() << endl ;
156 if ( strlen( PyFuncName ) ) {
157 Automaton()->PyLock() ;
158 thePyRunMethod = Automaton()->PyFunction( PyFuncName ) ;
159 if ( (*aPythonFunction).length() ) {
160 if ( thePyRunMethod == NULL ) {
162 aPyFunc += "import InitPyRunMethod\n" ;
163 for ( i = 0 ; i < (*aPythonFunction).length() ; i++ ) {
164 aPyFunc += (*aPythonFunction)[ i ] ;
167 aPyFunc += "InitPyRunMethod.RunMethod( " ;
168 aPyFunc += PyFuncName ;
170 /*cdebug *///cout<< "InitPyDynInvoke PyRun_SimpleString " << endl << aPyFunc << endl ;
171 // if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
172 if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
173 cdebug << ThreadNo() << " " << Name() << " PyRunSimpleString ERROR " << endl << aPyFunc << endl ;
174 PyFuncRunned( false ) ;
179 PyFuncRunned( true ) ;
180 thePyRunMethod = MyPyRunMethod ;
182 Automaton()->PyFunction( PyFuncName , thePyRunMethod ) ;
183 cdebug << ThreadNo() << "PyRunSimpleString( " << (*aPythonFunction)[ 0 ] << " ) " << endl ;
187 Automaton()->PyUnLock() ;
188 cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod " << thePyRunMethod << " "
189 << thePyRunMethod->ob_refcnt << endl ;
190 return thePyRunMethod ;
193 else if ( thePyRunMethod ) {
194 Automaton()->PyUnLock() ;
195 cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod " << thePyRunMethod << " "
196 << thePyRunMethod->ob_refcnt << endl ;
197 return thePyRunMethod ;
199 Automaton()->PyUnLock() ;
202 cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod Null Err " << Err << endl ;
207 extern "C" PyObject * PyRunMethod( PyObject * dummy , PyObject * Args ) {
208 PyObject * Result = NULL ;
209 PyObject * Temp = NULL ;
210 if ( PyArg_ParseTuple( Args , "O:set_callback" , & Temp ) ) {
211 // cout << "PyArg_ParsedTuple" << endl ;
212 if ( !PyCallable_Check( Temp ) ) {
213 // PyErr_SetString( PyExc_TypeError , "PyRunMethod must be callable" ) ;
214 // cout << "PyRunMethod must be callable" << endl ;
218 Py_XDECREF( MyPyRunMethod ) ;
219 MyPyRunMethod = Temp ;
220 Py_INCREF( Py_None ) ;
226 bool GraphExecutor::InNode::PyDynInvoke( PyObject * MyPyRunMethod ,
228 ServicesAnyData * inParams , int nInParams ,
229 ServicesAnyData * outParams , int nOutParams ) {
234 int n_in = nInParams ;
235 int n_out = nOutParams ;
238 cdebug_in << ThreadNo() << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method
239 << " " << n_in << " InArgs " << n_out << " OutArgs MyPyRunMethod " ;
240 if ( MyPyRunMethod ) {
241 cdebug << MyPyRunMethod << " " << MyPyRunMethod->ob_refcnt << endl ;
244 cdebug << " NULL" << endl ;
250 PyObject * ArgsList = NULL ;
251 PyObject * ArgValue = NULL ;
252 PyObject * Result = NULL ;
253 PyObject * MyPyObjRefList = NULL ;
254 PyObject * ResultObj = NULL ;
255 PyObject * MyPyObjIorList = NULL ;
256 PyObject * ResultIor = NULL ;
258 CORBA::Object_ptr ObjRef ;
261 if ( !PyCallable_Check( MyPyRunMethod ) ) {
266 ArgsList = PyTuple_New( n_in ) ;
268 for ( i = 0 ; i < n_in ; i++ ) {
269 data = inParams[i].Value ;
270 sname = inParams[i].Name.c_str() ;
271 switch ( data.type()->kind() ) {
272 case CORBA::tk_string : {
275 ArgValue = Py_BuildValue( "s" , t ) ;
276 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
277 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << t << " (string) "
278 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
279 << ArgValue->ob_refcnt << endl ;
282 case CORBA::tk_boolean : {
284 data >>= (CORBA::Any::to_boolean ) b ;
285 ArgValue = Py_BuildValue( "b" , b ) ;
286 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
287 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << b
288 << " (boolean) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
289 << ArgValue->ob_refcnt << endl ;
292 case CORBA::tk_char : {
294 data >>= (CORBA::Any::to_char ) c ;
295 ArgValue = Py_BuildValue( "c" , c ) ;
296 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
297 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << c
298 << " (char) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
299 << ArgValue->ob_refcnt << endl ;
302 case CORBA::tk_short : {
305 ArgValue = Py_BuildValue( "h" , s ) ;
306 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
307 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << s
308 << " (short) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
309 << ArgValue->ob_refcnt << endl ;
312 case CORBA::tk_long : {
315 ArgValue = Py_BuildValue( "l" , l ) ;
316 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
317 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
318 << " (long) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
319 << ArgValue->ob_refcnt << endl ;
322 case CORBA::tk_float : {
325 ArgValue = Py_BuildValue( "f" , f ) ;
326 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
327 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << f
328 << " (float) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
329 << ArgValue->ob_refcnt << endl ;
332 case CORBA::tk_double : {
335 ArgValue = Py_BuildValue( "d" , d ) ;
336 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
337 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << d
338 << " (double) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
339 << ArgValue->ob_refcnt << endl ;
342 case CORBA::tk_objref : {
343 MyPyObjRefList = PyTuple_New( 1 ) ;
344 PyObject * ObjValue ;
346 IORObjRef = ObjectToString( ObjRef ) ;
347 ObjValue = Py_BuildValue( "s" , IORObjRef ) ;
348 PyTuple_SetItem( MyPyObjRefList , 0 , ObjValue ) ;
349 cdebug << "ArgIn" << i << " : " << sname << " " << method << " " << " Value " << IORObjRef << " (objref) "
350 << MyPyObjRef->ob_refcnt << "/" << MyPyObjRefList->ob_refcnt << endl ;
351 // ResultObj = PyEval_CallObject( MyPyObjRef , MyPyObjRefList ) ;
352 ResultObj = PyEvalCallObject( MyPyObjRef , MyPyObjRefList ) ;
353 cdebug << "ObjValue->ob_refcnt" << ObjValue->ob_refcnt << endl ;
354 ArgValue = Py_BuildValue( "O" , ResultObj ) ;
355 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
356 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value (objref) ArgsList->ob_refcnt"
357 << ArgsList->ob_refcnt << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
358 cdebug << "MyPyObjRefList->ob_refcnt " << MyPyObjRefList->ob_refcnt-1 << endl ;
359 Py_DECREF( MyPyObjRefList ) ;
360 if ( CORBA::is_nil( ObjRef ) ) {
364 cdebug << "ResultObj->ob_refcnt " << ResultObj->ob_refcnt-1 << endl ;
365 Py_DECREF( ResultObj ) ;
370 cdebug << "ArgIn" << i << " : " << sname << " Value " << "(other ERROR)" << endl ;
375 // Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
376 Result = PyEvalCallObject( MyPyRunMethod , ArgsList ) ;
378 cdebug << "ArgsList->ob_refcnt" << ArgsList->ob_refcnt << endl ;
380 if ( Result == NULL ) {
381 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " " << method << " Error Result == NULL"
386 for ( i = 0 ; i < n_out ; i++ ) {
387 data = outParams[i].Value ;
388 sname = outParams[i].Name.c_str() ;
389 switch ( data.type()->kind() ) {
390 case CORBA::tk_string : {
392 if ( PyTuple_Check( Result ) ) {
393 ArgValue = PyTuple_GetItem( Result , i ) ;
398 if ( !PyString_Check( ArgValue ) ) {
399 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (string)" << endl ;
402 t = PyString_AsString( ArgValue ) ;
405 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << t << " (string)"
406 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
407 << ArgValue->ob_refcnt << endl ;
410 case CORBA::tk_boolean : {
412 if ( PyTuple_Check( Result ) ) {
413 ArgValue = PyTuple_GetItem( Result , i ) ;
418 if ( !PyInt_Check( ArgValue ) ) {
419 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (boolean)" << endl ;
422 b = PyInt_AsLong( ArgValue ) ;
424 data <<= (CORBA::Any::from_boolean ) b ;
425 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << b << " (boolean)"
426 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
427 << ArgValue->ob_refcnt << endl ;
430 case CORBA::tk_char : {
431 unsigned char c = 0 ;
432 if ( PyTuple_Check( Result ) ) {
433 ArgValue = PyTuple_GetItem( Result , i ) ;
438 if ( !PyInt_Check( ArgValue ) ) {
439 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (char)" << endl ;
442 c = PyInt_AsLong( ArgValue ) ;
444 data <<= (CORBA::Any::from_char ) c ;
445 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << c << " (char)"
446 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
447 << ArgValue->ob_refcnt << endl ;
450 case CORBA::tk_short : {
452 if ( PyTuple_Check( Result ) ) {
453 ArgValue = PyTuple_GetItem( Result , i ) ;
458 if ( !PyInt_Check( ArgValue ) ) {
459 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (short)" << endl ;
462 s = PyInt_AsLong( ArgValue ) ;
465 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << s << " (short)"
466 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
467 << ArgValue->ob_refcnt << endl ;
470 case CORBA::tk_long : {
472 if ( PyTuple_Check( Result ) ) {
473 ArgValue = PyTuple_GetItem( Result , i ) ;
478 if ( PyLong_Check( ArgValue ) ) {
479 l = PyLong_AsLong( ArgValue ) ;
481 else if ( PyInt_Check( ArgValue ) ) {
482 l = PyInt_AsLong( ArgValue ) ;
485 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (CORBA::tk_long)" << endl ;
488 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << l << " (long)"
489 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
490 << ArgValue->ob_refcnt << endl ;
493 case CORBA::tk_float : {
495 if ( PyTuple_Check( Result ) ) {
496 ArgValue = PyTuple_GetItem( Result , i ) ;
501 if ( !PyFloat_Check( ArgValue ) ) {
502 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (float)" << endl ;
505 f = PyFloat_AsDouble( ArgValue ) ;
508 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << f << " (float)"
509 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
510 << ArgValue->ob_refcnt << endl ;
513 case CORBA::tk_double : {
515 if ( PyTuple_Check( Result ) ) {
516 ArgValue = PyTuple_GetItem( Result , i ) ;
521 if ( !PyFloat_Check( ArgValue ) ) {
522 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (double)" << endl ;
525 d = PyFloat_AsDouble( ArgValue ) ;
528 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << d << " (double)"
529 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
530 << ArgValue->ob_refcnt << endl ;
533 case CORBA::tk_objref : {
535 MyPyObjIorList = PyTuple_New( 1 ) ;
536 if ( PyTuple_Check( Result ) ) {
537 ObjIor = PyTuple_GetItem( Result , i ) ;
542 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(object reference) "
543 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ObjIor->ob_refcnt"
544 << ObjIor->ob_refcnt << endl ;
545 Py_INCREF( ObjIor ) ;
546 // PyObject_Print( ObjIor , stdout , 0 ) ;
547 PyTuple_SetItem( MyPyObjIorList , 0 , ObjIor ) ;
548 // ResultIor = PyEval_CallObject( MyPyObjIor , MyPyObjIorList ) ;
549 ResultIor = PyEvalCallObject( MyPyObjIor , MyPyObjIorList ) ;
550 cdebug << "ObjIor->ob_refcnt " << ObjIor->ob_refcnt-1 << endl ;
551 Py_DECREF( ObjIor ) ;
552 cdebug << "MyPyObjIorList->ob_refcnt " << MyPyObjIorList->ob_refcnt-1 << endl ;
553 Py_DECREF( MyPyObjIorList ) ;
554 cdebug << "MyPyObjIor->ob_refcnt " << MyPyObjIor->ob_refcnt << endl ;
557 IOR = PyString_AsString( ResultIor ) ;
558 ObjRef = StringToObject( IOR ) ;
560 IORObjRef = ObjectToString( ObjRef ) ;
561 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << IORObjRef << " (objref) "
563 if ( CORBA::is_nil( ObjRef ) ) {
567 cdebug << "ResultIor->ob_refcnt " << ResultIor->ob_refcnt-1 << endl ;
568 Py_DECREF( ResultIor ) ;
572 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Error ResultIor == NULL Node "
573 << Name() << " method " << method << " " << endl ;
579 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(other ERROR)" << endl ;
582 outParams[i].Value = data ;
585 cdebug << "Result->ob_refcnt" << Result->ob_refcnt-1 << endl ;
586 Py_DECREF( Result ) ;
589 cdebug << "GraphExecutor::InNode::PyDynInvoke ArgsList->ob_refcnt"
590 << ArgsList->ob_refcnt-1 << endl ;
591 Py_DECREF( ArgsList ) ;
594 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method << " " << RetVal
601 bool GraphExecutor::InNode::PyRunSimpleString( char* thePyString )
603 const bool ErrorValue = true;
606 MESSAGE( pthread_self() << "Python method beginning : " << thePyString );
607 cdebug_in << pthread_self() << "Python method beginning : " << thePyString << endl ;
608 aRet = PyRun_SimpleString( thePyString );
609 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
610 //aRet = _OutNode->SuperVisionContainer()->ActivatePythonExecution( thePyString ) ;
611 MESSAGE( pthread_self() << "Python method finished." );
612 cdebug_out << pthread_self() << "Python method finished." << endl ;
614 MESSAGE( pthread_self() << "ERROR: Exception caught running Python method." );
615 cdebug_out << pthread_self() << "ERROR: Exception caught running Python method."
617 MESSAGE( " Python was reinitialized. Previous Python definitions are lost" );
618 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
621 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
622 _OutNode->PyInitialized( false );
628 PyObject * GraphExecutor::InNode::PyEvalCallObject( PyObject * MyPyRunMethod ,
629 PyObject * ArgsList ) {
630 cdebug_in << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
631 PyObject * Result = NULL ;
633 MESSAGE( pthread_self() << "PyEval_CallObject method beginning : " );
634 cdebug << pthread_self() << "PyEval_CallObject method beginning : " << Name() << endl ;
635 Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
636 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
637 //Result = _OutNode->SuperVisionContainer()->ActivatePythonExecution( MyPyRunMethod , ArgsList ) ;
638 MESSAGE( pthread_self() << "PyEval_CallObject method finished. Result " << Result );
639 cdebug << pthread_self() << "PyEval_CallObject method finished. Result " << Result << endl ;
640 cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
642 MESSAGE( pthread_self() << "ERROR: Exception caught PyEval_CallObject Python method. Result " << Result );
643 cdebug << pthread_self() << "ERROR: Exception caught PyEval_CallObject Python method. Result "
645 MESSAGE( " Python was reinitialized. Previous Python definitions are lost Py_IsInitialized " << Py_IsInitialized() );
646 //JR ===> fatal error in python : no current thread
647 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
650 Automaton()->PyInitModule( false ) ;
651 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
652 _OutNode->PyInitialized( false );
654 if ( Result == NULL ) {
655 Kill() ; // Reset of _ThreadId
657 cdebug_out << "Executor::InNode::PyEvalCallObject ERROR catched " << Name()
658 << " Py_IsInitialized " << Py_IsInitialized() << endl ;