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 #define PyDynInvokeTrace 0
227 bool GraphExecutor::InNode::PyDynInvoke( PyObject * MyPyRunMethod ,
229 ServicesAnyData * inParams , int nInParams ,
230 ServicesAnyData * outParams , int nOutParams ) {
235 int n_in = nInParams ;
236 int n_out = nOutParams ;
240 cdebug_in << ThreadNo() << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method
241 << " " << n_in << " InArgs " << n_out << " OutArgs MyPyRunMethod " ;
243 if ( MyPyRunMethod ) {
245 cdebug << MyPyRunMethod << " " << MyPyRunMethod->ob_refcnt << endl ;
250 cdebug << " NULL" << endl ;
257 PyObject * ArgsList = NULL ;
258 PyObject * ArgValue = NULL ;
259 PyObject * Result = NULL ;
260 PyObject * MyPyObjRefList = NULL ;
261 PyObject * ResultObj = NULL ;
262 PyObject * MyPyObjIorList = NULL ;
263 PyObject * ResultIor = NULL ;
265 CORBA::Object_ptr ObjRef ;
268 if ( !PyCallable_Check( MyPyRunMethod ) ) {
273 ArgsList = PyTuple_New( n_in ) ;
275 for ( i = 0 ; i < n_in ; i++ ) {
276 data = inParams[i].Value ;
277 sname = inParams[i].Name.c_str() ;
278 switch ( data.type()->kind() ) {
279 case CORBA::tk_string : {
282 PyObject * ArgValue = Py_BuildValue( "s" , t ) ;
283 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
285 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << t << " (string) "
286 << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
287 << ArgValue->ob_refcnt << endl ;
291 case CORBA::tk_boolean : {
293 data >>= (CORBA::Any::to_boolean ) b ;
294 PyObject * ArgValue = Py_BuildValue( "b" , b ) ;
295 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
297 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << b
298 << " (boolean) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
299 << ArgValue->ob_refcnt << endl ;
303 case CORBA::tk_char : {
305 data >>= (CORBA::Any::to_char ) c ;
306 PyObject * ArgValue = Py_BuildValue( "c" , c ) ;
307 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
309 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << c
310 << " (char) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
311 << ArgValue->ob_refcnt << endl ;
315 case CORBA::tk_short : {
318 PyObject * ArgValue = Py_BuildValue( "h" , s ) ;
319 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
321 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << s
322 << " (short) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
323 << ArgValue->ob_refcnt << endl ;
327 case CORBA::tk_long : {
330 PyObject * ArgValue = Py_BuildValue( "l" , l ) ;
332 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
333 << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
335 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
337 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
338 << " (long) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
339 << ArgValue->ob_refcnt << endl ;
343 case CORBA::tk_float : {
346 PyObject * ArgValue = Py_BuildValue( "f" , f ) ;
347 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
349 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << f
350 << " (float) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
351 << ArgValue->ob_refcnt << endl ;
355 case CORBA::tk_double : {
358 PyObject * ArgValue = Py_BuildValue( "d" , d ) ;
359 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
361 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << d
362 << " (double) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
363 << ArgValue->ob_refcnt << endl ;
367 case CORBA::tk_objref : {
368 MyPyObjRefList = PyTuple_New( 1 ) ;
369 PyObject * ObjValue ;
371 IORObjRef = ObjectToString( ObjRef ) ;
372 ObjValue = Py_BuildValue( "s" , IORObjRef ) ;
373 PyTuple_SetItem( MyPyObjRefList , 0 , ObjValue ) ;
375 cdebug << "ArgIn" << i << " : " << sname << " " << method << " " << " Value " << IORObjRef << " (objref) "
376 << MyPyObjRef->ob_refcnt << "/" << MyPyObjRefList->ob_refcnt << endl ;
378 // ResultObj = PyEval_CallObject( MyPyObjRef , MyPyObjRefList ) ;
379 ResultObj = PyEvalCallObject( "PyObjRef" , MyPyObjRef , MyPyObjRefList ) ;
381 cdebug << "ObjValue->ob_refcnt" << ObjValue->ob_refcnt << endl ;
383 ArgValue = Py_BuildValue( "O" , ResultObj ) ;
384 PyTuple_SetItem( ArgsList , i , ArgValue ) ;
386 cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value (objref) ArgsList->ob_refcnt"
387 << ArgsList->ob_refcnt << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
388 cdebug << "MyPyObjRefList->ob_refcnt " << MyPyObjRefList->ob_refcnt-1 << endl ;
390 Py_DECREF( MyPyObjRefList ) ;
391 if ( CORBA::is_nil( ObjRef ) ) {
396 cdebug << "ResultObj->ob_refcnt " << ResultObj->ob_refcnt-1 << endl ;
398 Py_DECREF( ResultObj ) ;
403 cdebug << "ArgIn" << i << " : " << sname << " Value " << "(other ERROR)" << endl ;
408 // Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
409 Result = PyEvalCallObject( method , MyPyRunMethod , ArgsList ) ;
412 cdebug << "ArgsList->ob_refcnt" << ArgsList->ob_refcnt << endl ;
415 if ( Result == NULL ) {
416 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " " << method << " Error Result == NULL"
421 for ( i = 0 ; i < n_out ; i++ ) {
422 data = outParams[i].Value ;
423 sname = outParams[i].Name.c_str() ;
424 switch ( data.type()->kind() ) {
425 case CORBA::tk_string : {
427 PyObject * ArgValue ;
428 if ( PyTuple_Check( Result ) ) {
429 ArgValue = PyTuple_GetItem( Result , i ) ;
434 if ( !PyString_Check( ArgValue ) ) {
435 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (string)" << endl ;
439 t = PyString_AsString( ArgValue ) ;
443 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << t << " (string)"
444 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
445 << ArgValue->ob_refcnt << endl ;
449 case CORBA::tk_boolean : {
451 PyObject * ArgValue ;
452 if ( PyTuple_Check( Result ) ) {
453 ArgValue = PyTuple_GetItem( Result , i ) ;
458 if ( !PyInt_Check( ArgValue ) ) {
459 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (boolean)" << endl ;
463 b = PyInt_AsLong( ArgValue ) ;
465 data <<= (CORBA::Any::from_boolean ) b ;
467 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << b << " (boolean)"
468 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
469 << ArgValue->ob_refcnt << endl ;
473 case CORBA::tk_char : {
474 unsigned char c = 0 ;
475 PyObject * ArgValue ;
476 if ( PyTuple_Check( Result ) ) {
477 ArgValue = PyTuple_GetItem( Result , i ) ;
482 //JR 04.04.2005 Debug if ( !PyInt_Check( ArgValue ) ) {
483 //Difficult to understand that behavior ... Python char type is a string of length 1 !
484 if ( !PyString_Check( ArgValue ) ) {
485 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (char)" << endl ;
489 c = PyInt_AsLong( ArgValue ) ;
491 data <<= (CORBA::Any::from_char ) c ;
493 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << c << " (char)"
494 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
495 << ArgValue->ob_refcnt << endl ;
499 case CORBA::tk_short : {
501 PyObject * ArgValue ;
502 if ( PyTuple_Check( Result ) ) {
503 ArgValue = PyTuple_GetItem( Result , i ) ;
508 if ( !PyInt_Check( ArgValue ) ) {
509 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (short)" << endl ;
513 s = PyInt_AsLong( ArgValue ) ;
517 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << s << " (short)"
518 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
519 << ArgValue->ob_refcnt << endl ;
523 case CORBA::tk_long : {
525 PyObject * ArgValue ;
526 if ( PyTuple_Check( Result ) ) {
527 ArgValue = PyTuple_GetItem( Result , i ) ;
532 if ( PyLong_Check( ArgValue ) ) {
533 l = PyLong_AsLong( ArgValue ) ;
535 else if ( PyInt_Check( ArgValue ) ) {
536 l = PyInt_AsLong( ArgValue ) ;
539 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (CORBA::tk_long)" << endl ;
544 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << l << " (long)"
545 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
546 << ArgValue->ob_refcnt << endl ;
550 case CORBA::tk_float : {
552 PyObject * ArgValue ;
553 if ( PyTuple_Check( Result ) ) {
554 ArgValue = PyTuple_GetItem( Result , i ) ;
559 if ( !PyFloat_Check( ArgValue ) ) {
560 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (float)" << endl ;
564 f = PyFloat_AsDouble( ArgValue ) ;
568 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << f << " (float)"
569 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
570 << ArgValue->ob_refcnt << endl ;
574 case CORBA::tk_double : {
576 PyObject * ArgValue ;
577 if ( PyTuple_Check( Result ) ) {
578 ArgValue = PyTuple_GetItem( Result , i ) ;
583 if ( !PyFloat_Check( ArgValue ) ) {
584 cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (double)" << endl ;
588 d = PyFloat_AsDouble( ArgValue ) ;
592 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << d << " (double)"
593 << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
594 << ArgValue->ob_refcnt << endl ;
598 case CORBA::tk_objref : {
600 MyPyObjIorList = PyTuple_New( 1 ) ;
601 if ( PyTuple_Check( Result ) ) {
602 ObjIor = PyTuple_GetItem( Result , i ) ;
608 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(object reference) "
609 << " Result->ob_refcnt" << Result->ob_refcnt << " ObjIor->ob_refcnt"
610 << ObjIor->ob_refcnt << endl ;
612 Py_INCREF( ObjIor ) ;
613 // PyObject_Print( ObjIor , stdout , 0 ) ;
614 PyTuple_SetItem( MyPyObjIorList , 0 , ObjIor ) ;
615 // ResultIor = PyEval_CallObject( MyPyObjIor , MyPyObjIorList ) ;
616 ResultIor = PyEvalCallObject( "PyObjIor" , MyPyObjIor , MyPyObjIorList ) ;
618 cdebug << "ObjIor->ob_refcnt " << ObjIor->ob_refcnt-1 << endl ;
620 Py_DECREF( ObjIor ) ;
622 cdebug << "MyPyObjIorList->ob_refcnt " << MyPyObjIorList->ob_refcnt-1 << endl ;
624 Py_DECREF( MyPyObjIorList ) ;
626 cdebug << "MyPyObjIor->ob_refcnt " << MyPyObjIor->ob_refcnt << endl ;
630 IOR = PyString_AsString( ResultIor ) ;
631 ObjRef = StringToObject( IOR ) ;
633 IORObjRef = ObjectToString( ObjRef ) ;
635 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << IORObjRef << " (objref) "
638 if ( CORBA::is_nil( ObjRef ) ) {
643 cdebug << "ResultIor->ob_refcnt " << ResultIor->ob_refcnt-1 << endl ;
645 Py_DECREF( ResultIor ) ;
649 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Error ResultIor == NULL Node "
650 << Name() << " method " << method << " " << endl ;
656 cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(other ERROR)" << endl ;
660 outParams[i].Value = data ;
664 // for ( k = 0 ; k < n_out ; k++ ) {
665 // cdebug << "Result" << k << "->ob_refcnt " << PyTuple_GetItem( Result , k )->ob_refcnt << endl ;
666 // Py_DECREF( PyTuple_GetItem( Result , k ) ) ;
670 cdebug << "InNode::PyDynInvoke Result->ob_refcnt " << Result->ob_refcnt-1 << endl ;
672 Py_DECREF( Result ) ;
676 // for ( k = 0 ; k < n_in ; k++ ) {
677 // cdebug << "ArgsList" << k << "->ob_refcnt " << PyTuple_GetItem( ArgsList , k )->ob_refcnt << endl ;
678 // Py_DECREF( PyTuple_GetItem( ArgsList , k ) ) ;
682 cdebug << "InNode::PyDynInvoke ArgsList->ob_refcnt " << ArgsList->ob_refcnt-1 << endl ;
684 Py_DECREF( ArgsList ) ;
688 cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method << " " << RetVal
696 bool GraphExecutor::InNode::PyRunSimpleString( char* thePyString )
698 const bool ErrorValue = true;
701 MESSAGE( pthread_self() << "Python method beginning : " << thePyString );
703 cdebug_in << pthread_self() << "Python method beginning : " << thePyString << endl ;
705 aRet = PyRun_SimpleString( thePyString );
706 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
707 //aRet = _OutNode->SuperVisionContainer()->ActivatePythonExecution( thePyString ) ;
708 MESSAGE( pthread_self() << "Python method finished." );
710 cdebug_out << pthread_self() << "Python method finished." << endl ;
713 MESSAGE( pthread_self() << "ERROR: Exception caught running Python method." );
714 cdebug_out << pthread_self() << "ERROR: Exception caught running Python method."
716 MESSAGE( " Python was reinitialized. Previous Python definitions are lost" );
717 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
720 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
721 _OutNode->PyInitialized( false );
727 PyObject * GraphExecutor::InNode::PyEvalCallObject( const char *method ,
728 PyObject * MyPyRunMethod ,
729 PyObject * ArgsList ) {
730 // cdebug_in << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
731 PyObject * Result = NULL ;
733 // MESSAGE( pthread_self() << "PyEval_CallObject " << Name() << " method beginning : " << method );
734 // cdebug << pthread_self() << "PyEval_CallObject " << Name() << " method beginning : " << method << endl ;
735 Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
736 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
737 //Result = _OutNode->SuperVisionContainer()->ActivatePythonExecution( MyPyRunMethod , ArgsList ) ;
738 // MESSAGE( pthread_self() << "PyEval_CallObject method finished. Result " << Result );
739 // cdebug << pthread_self() << "PyEval_CallObject method finished. Result " << Result << endl ;
740 // cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
742 MESSAGE( pthread_self() << "ERROR: Exception caught PyEval_CallObject " << Name()
743 << " Python method " << method << ". Result " << Result );
744 cdebug << pthread_self() << "ERROR: Exception caught PyEval_CallObject " << Name()
745 << " Python method " << method << ". Result " << Result << endl ;
746 MESSAGE( " Python was reinitialized. Previous Python definitions are lost Py_IsInitialized " << Py_IsInitialized() );
747 //JR ===> fatal error in python : no current thread
748 // asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
751 Automaton()->PyInitModule( false ) ;
752 Py_InitModule( "InitPyRunMethod" , MethodPyRunMethod );
753 _OutNode->PyInitialized( false );
755 if ( Result == NULL ) {
756 Kill() ; // Reset of _ThreadId
758 // cdebug << "Executor::InNode::PyEvalCallObject ERROR catched " << Name()
759 // << " Py_IsInitialized " << Py_IsInitialized() << endl ;
761 // cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;