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 PyObject * 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 PyObject * 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 PyObject * 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 PyObject * 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 PyObject * ArgValue = Py_BuildValue( "l" , l ) ;
316 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
317 << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
318 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
319 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
320 << " (long) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
321 << ArgValue->ob_refcnt << endl ;
324 case CORBA::tk_float : {
327 PyObject * ArgValue = Py_BuildValue( "f" , f ) ;
328 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
329 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << f
330 << " (float) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
331 << ArgValue->ob_refcnt << endl ;
334 case CORBA::tk_double : {
337 PyObject * ArgValue = Py_BuildValue( "d" , d ) ;
338 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
339 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << d
340 << " (double) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
341 << ArgValue->ob_refcnt << endl ;
344 case CORBA::tk_objref : {
345 MyPyObjRefList = PyTuple_New( 1 ) ;
346 PyObject * ObjValue ;
348 IORObjRef = ObjectToString( ObjRef ) ;
349 ObjValue = Py_BuildValue( "s" , IORObjRef ) ;
350 PyTuple_SetItem( MyPyObjRefList , 0 , ObjValue ) ;
351 cdebug << "ArgIn" << i << " : " << sname << " " << method << " " << " Value " << IORObjRef << " (objref) "
352 << MyPyObjRef->ob_refcnt << "/" << MyPyObjRefList->ob_refcnt << endl ;
353 // ResultObj = PyEval_CallObject( MyPyObjRef , MyPyObjRefList ) ;
354 ResultObj = PyEvalCallObject( "PyObjRef" , MyPyObjRef , MyPyObjRefList ) ;
355 cdebug << "ObjValue->ob_refcnt" << ObjValue->ob_refcnt << endl ;
356 ArgValue = Py_BuildValue( "O" , ResultObj ) ;
357 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
358 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value (objref) ArgsList->ob_refcnt"
359 << ArgsList->ob_refcnt << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
360 cdebug << "MyPyObjRefList->ob_refcnt " << MyPyObjRefList->ob_refcnt-1 << endl ;
361 Py_DECREF( MyPyObjRefList ) ;
362 if ( CORBA::is_nil( ObjRef ) ) {
366 cdebug << "ResultObj->ob_refcnt " << ResultObj->ob_refcnt-1 << endl ;
367 Py_DECREF( ResultObj ) ;
372 cdebug << "ArgIn" << i << " : " << sname << " Value " << "(other ERROR)" << endl ;
377 // Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
378 Result = PyEvalCallObject( method , MyPyRunMethod , ArgsList ) ;
380 cdebug << "ArgsList->ob_refcnt" << ArgsList->ob_refcnt << endl ;
382 if ( Result == NULL ) {
383 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " " << method << " Error Result == NULL"
388 for ( i = 0 ; i < n_out ; i++ ) {
389 data = outParams[i].Value ;
390 sname = outParams[i].Name.c_str() ;
391 switch ( data.type()->kind() ) {
392 case CORBA::tk_string : {
394 PyObject * ArgValue ;
395 if ( PyTuple_Check( Result ) ) {
396 ArgValue = PyTuple_GetItem( Result , i ) ;
401 if ( !PyString_Check( ArgValue ) ) {
402 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (string)" << endl ;
405 t = PyString_AsString( ArgValue ) ;
408 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << t << " (string)"
409 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
410 << ArgValue->ob_refcnt << endl ;
413 case CORBA::tk_boolean : {
415 PyObject * ArgValue ;
416 if ( PyTuple_Check( Result ) ) {
417 ArgValue = PyTuple_GetItem( Result , i ) ;
422 if ( !PyInt_Check( ArgValue ) ) {
423 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (boolean)" << endl ;
426 b = PyInt_AsLong( ArgValue ) ;
428 data <<= (CORBA::Any::from_boolean ) b ;
429 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << b << " (boolean)"
430 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
431 << ArgValue->ob_refcnt << endl ;
434 case CORBA::tk_char : {
435 unsigned char c = 0 ;
436 PyObject * ArgValue ;
437 if ( PyTuple_Check( Result ) ) {
438 ArgValue = PyTuple_GetItem( Result , i ) ;
443 if ( !PyInt_Check( ArgValue ) ) {
444 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (char)" << endl ;
447 c = PyInt_AsLong( ArgValue ) ;
449 data <<= (CORBA::Any::from_char ) c ;
450 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << c << " (char)"
451 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
452 << ArgValue->ob_refcnt << endl ;
455 case CORBA::tk_short : {
457 PyObject * ArgValue ;
458 if ( PyTuple_Check( Result ) ) {
459 ArgValue = PyTuple_GetItem( Result , i ) ;
464 if ( !PyInt_Check( ArgValue ) ) {
465 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (short)" << endl ;
468 s = PyInt_AsLong( ArgValue ) ;
471 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << s << " (short)"
472 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
473 << ArgValue->ob_refcnt << endl ;
476 case CORBA::tk_long : {
478 PyObject * ArgValue ;
479 if ( PyTuple_Check( Result ) ) {
480 ArgValue = PyTuple_GetItem( Result , i ) ;
485 if ( PyLong_Check( ArgValue ) ) {
486 l = PyLong_AsLong( ArgValue ) ;
488 else if ( PyInt_Check( ArgValue ) ) {
489 l = PyInt_AsLong( ArgValue ) ;
492 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (CORBA::tk_long)" << endl ;
495 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << l << " (long)"
496 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
497 << ArgValue->ob_refcnt << endl ;
500 case CORBA::tk_float : {
502 PyObject * ArgValue ;
503 if ( PyTuple_Check( Result ) ) {
504 ArgValue = PyTuple_GetItem( Result , i ) ;
509 if ( !PyFloat_Check( ArgValue ) ) {
510 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (float)" << endl ;
513 f = PyFloat_AsDouble( ArgValue ) ;
516 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << f << " (float)"
517 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
518 << ArgValue->ob_refcnt << endl ;
521 case CORBA::tk_double : {
523 PyObject * ArgValue ;
524 if ( PyTuple_Check( Result ) ) {
525 ArgValue = PyTuple_GetItem( Result , i ) ;
530 if ( !PyFloat_Check( ArgValue ) ) {
531 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (double)" << endl ;
534 d = PyFloat_AsDouble( ArgValue ) ;
537 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << d << " (double)"
538 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
539 << ArgValue->ob_refcnt << endl ;
542 case CORBA::tk_objref : {
544 MyPyObjIorList = PyTuple_New( 1 ) ;
545 if ( PyTuple_Check( Result ) ) {
546 ObjIor = PyTuple_GetItem( Result , i ) ;
551 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(object reference) "
552 << " Result->ob_refcnt" << Result->ob_refcnt << " ObjIor->ob_refcnt"
553 << ObjIor->ob_refcnt << endl ;
554 Py_INCREF( ObjIor ) ;
555 // PyObject_Print( ObjIor , stdout , 0 ) ;
556 PyTuple_SetItem( MyPyObjIorList , 0 , ObjIor ) ;
557 // ResultIor = PyEval_CallObject( MyPyObjIor , MyPyObjIorList ) ;
558 ResultIor = PyEvalCallObject( "PyObjIor" , MyPyObjIor , MyPyObjIorList ) ;
559 cdebug << "ObjIor->ob_refcnt " << ObjIor->ob_refcnt-1 << endl ;
560 Py_DECREF( ObjIor ) ;
561 cdebug << "MyPyObjIorList->ob_refcnt " << MyPyObjIorList->ob_refcnt-1 << endl ;
562 Py_DECREF( MyPyObjIorList ) ;
563 cdebug << "MyPyObjIor->ob_refcnt " << MyPyObjIor->ob_refcnt << endl ;
566 IOR = PyString_AsString( ResultIor ) ;
567 ObjRef = StringToObject( IOR ) ;
569 IORObjRef = ObjectToString( ObjRef ) ;
570 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << IORObjRef << " (objref) "
572 if ( CORBA::is_nil( ObjRef ) ) {
576 cdebug << "ResultIor->ob_refcnt " << ResultIor->ob_refcnt-1 << endl ;
577 Py_DECREF( ResultIor ) ;
581 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Error ResultIor == NULL Node "
582 << Name() << " method " << method << " " << endl ;
588 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(other ERROR)" << endl ;
591 outParams[i].Value = data ;
595 // for ( k = 0 ; k < n_out ; k++ ) {
596 // cdebug << "Result" << k << "->ob_refcnt " << PyTuple_GetItem( Result , k )->ob_refcnt << endl ;
597 // Py_DECREF( PyTuple_GetItem( Result , k ) ) ;
600 cdebug << "InNode::PyDynInvoke Result->ob_refcnt " << Result->ob_refcnt-1 << endl ;
601 Py_DECREF( Result ) ;
605 // for ( k = 0 ; k < n_in ; k++ ) {
606 // cdebug << "ArgsList" << k << "->ob_refcnt " << PyTuple_GetItem( ArgsList , k )->ob_refcnt << endl ;
607 // Py_DECREF( PyTuple_GetItem( ArgsList , k ) ) ;
610 cdebug << "InNode::PyDynInvoke ArgsList->ob_refcnt " << ArgsList->ob_refcnt-1 << endl ;
611 Py_DECREF( ArgsList ) ;
614 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method << " " << RetVal
621 bool GraphExecutor::InNode::PyRunSimpleString( char* thePyString )
623 const bool ErrorValue = true;
626 MESSAGE( pthread_self() << "Python method beginning : " << thePyString );
627 cdebug_in << pthread_self() << "Python method beginning : " << thePyString << endl ;
628 aRet = PyRun_SimpleString( thePyString );
629 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
630 //aRet = _OutNode->SuperVisionContainer()->ActivatePythonExecution( thePyString ) ;
631 MESSAGE( pthread_self() << "Python method finished." );
632 cdebug_out << pthread_self() << "Python method finished." << endl ;
634 MESSAGE( pthread_self() << "ERROR: Exception caught running Python method." );
635 cdebug_out << pthread_self() << "ERROR: Exception caught running Python method."
637 MESSAGE( " Python was reinitialized. Previous Python definitions are lost" );
638 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
641 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
642 _OutNode->PyInitialized( false );
648 PyObject * GraphExecutor::InNode::PyEvalCallObject( const char *method ,
649 PyObject * MyPyRunMethod ,
650 PyObject * ArgsList ) {
651 // cdebug_in << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
652 PyObject * Result = NULL ;
654 // MESSAGE( pthread_self() << "PyEval_CallObject " << Name() << " method beginning : " << method );
655 // cdebug << pthread_self() << "PyEval_CallObject " << Name() << " method beginning : " << method << endl ;
656 Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
657 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
658 //Result = _OutNode->SuperVisionContainer()->ActivatePythonExecution( MyPyRunMethod , ArgsList ) ;
659 // MESSAGE( pthread_self() << "PyEval_CallObject method finished. Result " << Result );
660 // cdebug << pthread_self() << "PyEval_CallObject method finished. Result " << Result << endl ;
661 // cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
663 MESSAGE( pthread_self() << "ERROR: Exception caught PyEval_CallObject " << Name()
664 << " Python method " << method << ". Result " << Result );
665 cdebug << pthread_self() << "ERROR: Exception caught PyEval_CallObject " << Name()
666 << " Python method " << method << ". Result " << Result << endl ;
667 MESSAGE( " Python was reinitialized. Previous Python definitions are lost Py_IsInitialized " << Py_IsInitialized() );
668 //JR ===> fatal error in python : no current thread
669 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
672 Automaton()->PyInitModule( false ) ;
673 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
674 _OutNode->PyInitialized( false );
676 if ( Result == NULL ) {
677 Kill() ; // Reset of _ThreadId
679 // cdebug << "Executor::InNode::PyEvalCallObject ERROR catched " << Name()
680 // << " Py_IsInitialized " << Py_IsInitialized() << endl ;
682 // cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;