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 _OutNode->SuperVisionContainer()->ActivatePythonExecution( "InitPyRunMethod" , MethodPyRunMethod ) ;
41 // PyObject * Dictionnary = PyModule_GetDict( Module ) ;
42 // InitPyDynInvokeError = PyErr_NewException( "InitPyDynInvokeError" , NULL , NULL ) ;
43 // PyDict_SetItemString( Dictionnary , InitPyDynInvokeError ) ;
44 cdebug << ThreadNo() << "Py_Initialized() " << endl ;
47 //JR : Python documentation says that there is no sense to set a handler of synchronous
48 // signals as SIGSEGV and SIGFPE !!!
49 if ( Automaton()->PyFunction( "PyObjSignal" ) == NULL ) {
51 aPyFunc = "import signal\n" ;
52 aPyFunc += "import InitPyRunMethod\n" ;
53 aPyFunc += "import sys\n" ;
54 aPyFunc += "import CORBA\n" ;
55 aPyFunc += "import omniORB\n" ;
56 aPyFunc += "def PySignalHandler( aSignal , aStackFrame ) :\n" ;
57 aPyFunc += " print 'PySignalHandler(aSignal =',aSignal,',aStackFrame= ',aStackFrame,')'\n" ;
58 aPyFunc += "InitPyRunMethod.RunMethod( PySignalHandler )\n" ;
59 aPyFunc += "PrevHandler = signal.signal( signal.SIGSEGV , PySignalHandler )\n" ;
60 aPyFunc += "print 'PyObjSignal PrevHandler of SIGSEGV :', PrevHandler\n" ;
61 aPyFunc += "print 'PyObjSignal actual handler of SIGSEGV :', signal.getsignal( signal.SIGSEGV )\n" ;
62 // if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
63 if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
64 cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
65 Automaton()->PyUnLock() ;
68 MyPyObjSignal = MyPyRunMethod ;
69 Automaton()->PyFunction( "PyObjSignal" , MyPyObjSignal ) ;
72 MyPyObjSignal = Automaton()->PyFunction( "PyObjSignal" ) ;
76 // PyObjRef convert an IOR (string) to an Python ObjectReference
77 if ( Automaton()->PyFunction( "PyObjRef" ) == NULL ) {
79 aPyFunc = "import InitPyRunMethod\n" ;
80 aPyFunc += "import sys\n" ;
81 aPyFunc += "import CORBA\n" ;
82 aPyFunc += "import omniORB\n" ;
83 aPyFunc += "def PyObjRef( IORObjStr ) :\n" ;
84 aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
85 aPyFunc += " objref = orb.string_to_object( IORObjStr )\n" ;
86 aPyFunc += " return objref\n" ;
87 aPyFunc += "InitPyRunMethod.RunMethod( PyObjRef )\n" ;
88 // if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
89 if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
90 cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
91 Automaton()->PyUnLock() ;
94 MyPyObjRef = MyPyRunMethod ;
95 Automaton()->PyFunction( "PyObjRef" , MyPyObjRef ) ;
98 MyPyObjRef = Automaton()->PyFunction( "PyObjRef" ) ;
101 // PyObjRef convert an Python ObjectReference to an IOR (string)
102 if ( Automaton()->PyFunction( "PyObjIor" ) == NULL ) {
104 aPyFunc = "import InitPyRunMethod\n" ;
105 aPyFunc += "import sys\n" ;
106 aPyFunc += "import CORBA\n" ;
107 aPyFunc += "import omniORB\n" ;
108 aPyFunc += "def PyObjIor( ObjRef ) :\n" ;
109 aPyFunc += " orb = CORBA.ORB_init( sys.argv , CORBA.ORB_ID )\n" ;
110 aPyFunc += " objIor = orb.object_to_string( ObjRef )\n" ;
111 aPyFunc += " return objIor\n" ;
112 aPyFunc += "InitPyRunMethod.RunMethod( PyObjIor )\n" ;
113 // if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
114 if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
115 cdebug << ThreadNo() << " " << Name() << " PyRun_SimpleString ERROR " << endl << aPyFunc << endl ;
116 Automaton()->PyUnLock() ;
119 MyPyObjIor = MyPyRunMethod ;
120 Automaton()->PyFunction( "PyObjIor" , MyPyObjIor ) ;
123 MyPyObjIor = Automaton()->PyFunction( "PyObjIor" ) ;
125 Automaton()->PyUnLock() ;
127 cdebug_out << "InitPython" << endl ;
132 void GraphExecutor::InNode::RemovePyDynInvoke( char * PyFuncName ) {
133 // Automaton()->PyLock() ; // Already done ...
134 if ( Automaton()->ErasePyFunction( PyFuncName ) ) {
135 cdebug << "InNode::RemovePyDynInvoke( " << PyFuncName << " ) success" << endl ;
138 cdebug << "InNode::RemovePyDynInvoke( " << PyFuncName << " ) ERROR failed" << endl ;
140 // Automaton()->PyUnLock() ;
143 PyObject * GraphExecutor::InNode::InitPyDynInvoke( char * PyFuncName ,
144 const SUPERV::ListOfStrings * aPythonFunction ,
149 PyObject * thePyRunMethod = NULL ;
151 cdebug_in << "InitPyDynInvoke '" << PyFuncName << "' length " << (*aPythonFunction).length() << endl ;
153 if ( strlen( PyFuncName ) ) {
154 Automaton()->PyLock() ;
155 thePyRunMethod = Automaton()->PyFunction( PyFuncName ) ;
156 if ( (*aPythonFunction).length() ) {
157 if ( thePyRunMethod == NULL ) {
159 aPyFunc += "import InitPyRunMethod\n" ;
160 for ( i = 0 ; i < (*aPythonFunction).length() ; i++ ) {
161 aPyFunc += (*aPythonFunction)[ i ] ;
164 aPyFunc += "InitPyRunMethod.RunMethod( " ;
165 aPyFunc += PyFuncName ;
167 /*cdebug *///cout<< "InitPyDynInvoke PyRun_SimpleString " << endl << aPyFunc << endl ;
168 // if ( PyRun_SimpleString( (char *) aPyFunc.c_str() ) ) {
169 if ( PyRunSimpleString( (char *) aPyFunc.c_str() ) ) {
170 cdebug << ThreadNo() << " " << Name() << " PyRunSimpleString ERROR " << endl << aPyFunc << endl ;
171 PyFuncRunned( false ) ;
176 PyFuncRunned( true ) ;
177 thePyRunMethod = MyPyRunMethod ;
179 Automaton()->PyFunction( PyFuncName , thePyRunMethod ) ;
180 cdebug << ThreadNo() << "PyRunSimpleString( " << (*aPythonFunction)[ 0 ] << " ) " << endl ;
184 Automaton()->PyUnLock() ;
185 cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod " << thePyRunMethod << " "
186 << thePyRunMethod->ob_refcnt << endl ;
187 return thePyRunMethod ;
190 else if ( thePyRunMethod ) {
191 Automaton()->PyUnLock() ;
192 cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod " << thePyRunMethod << " "
193 << thePyRunMethod->ob_refcnt << endl ;
194 return thePyRunMethod ;
196 Automaton()->PyUnLock() ;
199 cdebug_out << "InitPyDynInvoke '" << PyFuncName << "' thePyRunMethod Null Err " << Err << endl ;
204 extern "C" PyObject * PyRunMethod( PyObject * dummy , PyObject * Args ) {
205 PyObject * Result = NULL ;
206 PyObject * Temp = NULL ;
207 if ( PyArg_ParseTuple( Args , "O:set_callback" , & Temp ) ) {
208 // cout << "PyArg_ParsedTuple" << endl ;
209 if ( !PyCallable_Check( Temp ) ) {
210 // PyErr_SetString( PyExc_TypeError , "PyRunMethod must be callable" ) ;
211 // cout << "PyRunMethod must be callable" << endl ;
215 Py_XDECREF( MyPyRunMethod ) ;
216 MyPyRunMethod = Temp ;
217 Py_INCREF( Py_None ) ;
223 bool GraphExecutor::InNode::PyDynInvoke( PyObject * MyPyRunMethod ,
225 ServicesAnyData * inParams , int nInParams ,
226 ServicesAnyData * outParams , int nOutParams ) {
231 int n_in = nInParams ;
232 int n_out = nOutParams ;
235 cdebug_in << ThreadNo() << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method
236 << " " << n_in << " InArgs " << n_out << " OutArgs MyPyRunMethod " ;
237 if ( MyPyRunMethod ) {
238 cdebug << MyPyRunMethod << " " << MyPyRunMethod->ob_refcnt << endl ;
241 cdebug << " NULL" << endl ;
247 PyObject * ArgsList = NULL ;
248 PyObject * ArgValue = NULL ;
249 PyObject * Result = NULL ;
250 PyObject * MyPyObjRefList = NULL ;
251 PyObject * ResultObj = NULL ;
252 PyObject * MyPyObjIorList = NULL ;
253 PyObject * ResultIor = NULL ;
255 CORBA::Object_ptr ObjRef ;
258 if ( !PyCallable_Check( MyPyRunMethod ) ) {
263 ArgsList = PyTuple_New( n_in ) ;
265 for ( i = 0 ; i < n_in ; i++ ) {
266 data = inParams[i].Value ;
267 sname = inParams[i].Name.c_str() ;
268 switch ( data.type()->kind() ) {
269 case CORBA::tk_string : {
272 ArgValue = Py_BuildValue( "s" , t ) ;
273 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
274 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << t << " (string) "
275 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
276 << ArgValue->ob_refcnt << endl ;
279 case CORBA::tk_boolean : {
281 data >>= (CORBA::Any::to_boolean ) b ;
282 ArgValue = Py_BuildValue( "b" , b ) ;
283 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
284 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << b
285 << " (boolean) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
286 << ArgValue->ob_refcnt << endl ;
289 case CORBA::tk_char : {
291 data >>= (CORBA::Any::to_char ) c ;
292 ArgValue = Py_BuildValue( "c" , c ) ;
293 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
294 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << c
295 << " (char) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
296 << ArgValue->ob_refcnt << endl ;
299 case CORBA::tk_short : {
302 ArgValue = Py_BuildValue( "h" , s ) ;
303 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
304 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << s
305 << " (short) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
306 << ArgValue->ob_refcnt << endl ;
309 case CORBA::tk_long : {
312 ArgValue = Py_BuildValue( "l" , l ) ;
313 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
314 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
315 << " (long) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
316 << ArgValue->ob_refcnt << endl ;
319 case CORBA::tk_float : {
322 ArgValue = Py_BuildValue( "f" , f ) ;
323 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
324 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << f
325 << " (float) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
326 << ArgValue->ob_refcnt << endl ;
329 case CORBA::tk_double : {
332 ArgValue = Py_BuildValue( "d" , d ) ;
333 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
334 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << d
335 << " (double) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
336 << ArgValue->ob_refcnt << endl ;
339 case CORBA::tk_objref : {
340 MyPyObjRefList = PyTuple_New( 1 ) ;
341 PyObject * ObjValue ;
343 IORObjRef = ObjectToString( ObjRef ) ;
344 ObjValue = Py_BuildValue( "s" , IORObjRef ) ;
345 PyTuple_SetItem( MyPyObjRefList , 0 , ObjValue ) ;
346 cdebug << "ArgIn" << i << " : " << sname << " " << method << " " << " Value " << IORObjRef << " (objref) "
347 << MyPyObjRef->ob_refcnt << "/" << MyPyObjRefList->ob_refcnt << endl ;
348 // ResultObj = PyEval_CallObject( MyPyObjRef , MyPyObjRefList ) ;
349 ResultObj = PyEvalCallObject( MyPyObjRef , MyPyObjRefList ) ;
350 cdebug << "ObjValue->ob_refcnt" << ObjValue->ob_refcnt << endl ;
351 ArgValue = Py_BuildValue( "O" , ResultObj ) ;
352 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
353 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value (objref) ArgsList->ob_refcnt"
354 << ArgsList->ob_refcnt << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
355 cdebug << "MyPyObjRefList->ob_refcnt " << MyPyObjRefList->ob_refcnt-1 << endl ;
356 Py_DECREF( MyPyObjRefList ) ;
357 if ( CORBA::is_nil( ObjRef ) ) {
361 cdebug << "ResultObj->ob_refcnt " << ResultObj->ob_refcnt-1 << endl ;
362 Py_DECREF( ResultObj ) ;
367 cdebug << "ArgIn" << i << " : " << sname << " Value " << "(other ERROR)" << endl ;
372 // Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
373 Result = PyEvalCallObject( MyPyRunMethod , ArgsList ) ;
375 cdebug << "ArgsList->ob_refcnt" << ArgsList->ob_refcnt << endl ;
377 if ( Result == NULL ) {
378 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " " << method << " Error Result == NULL"
383 for ( i = 0 ; i < n_out ; i++ ) {
384 data = outParams[i].Value ;
385 sname = outParams[i].Name.c_str() ;
386 switch ( data.type()->kind() ) {
387 case CORBA::tk_string : {
389 if ( PyTuple_Check( Result ) ) {
390 ArgValue = PyTuple_GetItem( Result , i ) ;
395 if ( !PyString_Check( ArgValue ) ) {
396 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (string)" << endl ;
399 t = PyString_AsString( ArgValue ) ;
402 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << t << " (string)"
403 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
404 << ArgValue->ob_refcnt << endl ;
407 case CORBA::tk_boolean : {
409 if ( PyTuple_Check( Result ) ) {
410 ArgValue = PyTuple_GetItem( Result , i ) ;
415 if ( !PyInt_Check( ArgValue ) ) {
416 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (boolean)" << endl ;
419 b = PyInt_AsLong( ArgValue ) ;
421 data <<= (CORBA::Any::from_boolean ) b ;
422 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << b << " (boolean)"
423 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
424 << ArgValue->ob_refcnt << endl ;
427 case CORBA::tk_char : {
428 unsigned char c = 0 ;
429 if ( PyTuple_Check( Result ) ) {
430 ArgValue = PyTuple_GetItem( Result , i ) ;
435 if ( !PyInt_Check( ArgValue ) ) {
436 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (char)" << endl ;
439 c = PyInt_AsLong( ArgValue ) ;
441 data <<= (CORBA::Any::from_char ) c ;
442 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << c << " (char)"
443 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
444 << ArgValue->ob_refcnt << endl ;
447 case CORBA::tk_short : {
449 if ( PyTuple_Check( Result ) ) {
450 ArgValue = PyTuple_GetItem( Result , i ) ;
455 if ( !PyInt_Check( ArgValue ) ) {
456 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (short)" << endl ;
459 s = PyInt_AsLong( ArgValue ) ;
462 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << s << " (short)"
463 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
464 << ArgValue->ob_refcnt << endl ;
467 case CORBA::tk_long : {
469 if ( PyTuple_Check( Result ) ) {
470 ArgValue = PyTuple_GetItem( Result , i ) ;
475 if ( PyLong_Check( ArgValue ) ) {
476 l = PyLong_AsLong( ArgValue ) ;
478 else if ( PyInt_Check( ArgValue ) ) {
479 l = PyInt_AsLong( ArgValue ) ;
482 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (CORBA::tk_long)" << endl ;
485 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << l << " (long)"
486 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
487 << ArgValue->ob_refcnt << endl ;
490 case CORBA::tk_float : {
492 if ( PyTuple_Check( Result ) ) {
493 ArgValue = PyTuple_GetItem( Result , i ) ;
498 if ( !PyFloat_Check( ArgValue ) ) {
499 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (float)" << endl ;
502 f = PyFloat_AsDouble( ArgValue ) ;
505 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << f << " (float)"
506 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
507 << ArgValue->ob_refcnt << endl ;
510 case CORBA::tk_double : {
512 if ( PyTuple_Check( Result ) ) {
513 ArgValue = PyTuple_GetItem( Result , i ) ;
518 if ( !PyFloat_Check( ArgValue ) ) {
519 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (double)" << endl ;
522 d = PyFloat_AsDouble( ArgValue ) ;
525 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << d << " (double)"
526 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
527 << ArgValue->ob_refcnt << endl ;
530 case CORBA::tk_objref : {
532 MyPyObjIorList = PyTuple_New( 1 ) ;
533 if ( PyTuple_Check( Result ) ) {
534 ObjIor = PyTuple_GetItem( Result , i ) ;
539 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(object reference) "
540 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ObjIor->ob_refcnt"
541 << ObjIor->ob_refcnt << endl ;
542 Py_INCREF( ObjIor ) ;
543 // PyObject_Print( ObjIor , stdout , 0 ) ;
544 PyTuple_SetItem( MyPyObjIorList , 0 , ObjIor ) ;
545 // ResultIor = PyEval_CallObject( MyPyObjIor , MyPyObjIorList ) ;
546 ResultIor = PyEvalCallObject( MyPyObjIor , MyPyObjIorList ) ;
547 cdebug << "ObjIor->ob_refcnt " << ObjIor->ob_refcnt-1 << endl ;
548 Py_DECREF( ObjIor ) ;
549 cdebug << "MyPyObjIorList->ob_refcnt " << MyPyObjIorList->ob_refcnt-1 << endl ;
550 Py_DECREF( MyPyObjIorList ) ;
551 cdebug << "MyPyObjIor->ob_refcnt " << MyPyObjIor->ob_refcnt << endl ;
554 IOR = PyString_AsString( ResultIor ) ;
555 ObjRef = StringToObject( IOR ) ;
557 IORObjRef = ObjectToString( ObjRef ) ;
558 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << IORObjRef << " (objref) "
560 if ( CORBA::is_nil( ObjRef ) ) {
564 cdebug << "ResultIor->ob_refcnt " << ResultIor->ob_refcnt-1 << endl ;
565 Py_DECREF( ResultIor ) ;
569 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Error ResultIor == NULL Node "
570 << Name() << " method " << method << " " << endl ;
576 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(other ERROR)" << endl ;
579 outParams[i].Value = data ;
582 cdebug << "Result->ob_refcnt" << Result->ob_refcnt-1 << endl ;
583 Py_DECREF( Result ) ;
586 cdebug << "GraphExecutor::InNode::PyDynInvoke ArgsList->ob_refcnt"
587 << ArgsList->ob_refcnt-1 << endl ;
588 Py_DECREF( ArgsList ) ;
591 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method << " " << RetVal
598 bool GraphExecutor::InNode::PyRunSimpleString( char* thePyString )
600 const bool ErrorValue = true;
603 MESSAGE( pthread_self() << "Python method beginning : " << thePyString );
604 cdebug_in << pthread_self() << "Python method beginning : " << thePyString << endl ;
605 // aRet = PyRun_SimpleString( thePyString );
606 aRet = _OutNode->SuperVisionContainer()->ActivatePythonExecution( thePyString ) ;
607 MESSAGE( pthread_self() << "Python method finished." );
608 cdebug_out << pthread_self() << "Python method finished." << endl ;
610 MESSAGE( pthread_self() << "ERROR: Exception caught running Python method." );
611 cdebug_out << pthread_self() << "ERROR: Exception caught running Python method."
613 MESSAGE( " Python was reinitialized. Previous Python definitions are lost" );
616 // Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
617 _OutNode->PyInitialized( false );
623 PyObject * GraphExecutor::InNode::PyEvalCallObject( PyObject * MyPyRunMethod ,
624 PyObject * ArgsList ) {
625 cdebug_in << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
626 PyObject * Result = NULL ;
628 MESSAGE( pthread_self() << "PyEval_CallObject method beginning : " );
629 cdebug << pthread_self() << "PyEval_CallObject method beginning : " << Name() << endl ;
630 // Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
631 Result = _OutNode->SuperVisionContainer()->ActivatePythonExecution( MyPyRunMethod , ArgsList ) ;
632 MESSAGE( pthread_self() << "PyEval_CallObject method finished. Result " << Result );
633 cdebug << pthread_self() << "PyEval_CallObject method finished. Result " << Result << endl ;
634 cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
636 MESSAGE( pthread_self() << "ERROR: Exception caught PyEval_CallObject Python method. Result " << Result );
637 cdebug << pthread_self() << "ERROR: Exception caught PyEval_CallObject Python method. Result "
639 // MESSAGE( " Python was reinitialized. Previous Python definitions are lost Py_IsInitialized " << Py_IsInitialized() );
640 //JR ===> fatal error in python : no current thread
643 // Automaton()->PyInitModule( false ) ;
644 // Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
645 // _OutNode->PyInitialized( false );
646 if ( Result == NULL ) {
647 Kill() ; // Reset of _ThreadId
649 cdebug_out << "Executor::InNode::PyEvalCallObject ERROR catched " << Name()
650 << " Py_IsInitialized " << Py_IsInitialized() << endl ;