Hi all!! .. I am New member to this group.
And also new to C/PYTHON API coding.
I am trying to have two way communication i,e i am calling from python to C and then from C to python.
I have no problem calling c func from python....
But problem is for calling C to Python
I am trying to call a python function multiple times by passing one parameter 'fun(param)' from C code .
I am getting segmentation fault error while executing .
The code i am is below...
# Python code..
import API # It is a shared library created by using 'Swig' Tool
class MyApp :
__init__(self, parent) # function to create GUI
//Code to create GUI.. (Text box)
API.function() ## here I am calling 'function()' (which is in 'call.c')
def fun(recv) :
//Here i am inserting the received(recv) value in GUI Text Widget.
return;
app = MyApp() //creating object to class 'MyApp'
// C code...
// call.c
function()
{
printf"Called from python\n"
call();
}
call()
{
while(first_tim e) {
Py_Initialise() ;
PyRun_SimpleStr ing("import pyfile"); //pyfile is my python file
}
PyRun_SimpleStr ing("pyfile.app .fun('SUCCESS') "); //fun is function inside pyfile and I am passing 'SUCCESS' as the parameter
// Py_Finalize();
}
To be more specific i am calling PyRun_SimpleStr ing("pyfile.fun ('SUCCESS')")
multiple times , initializing and importing only once...And Finalizing in the end .(If i initialize and finalize everytime i invoke the function i got segmentation fault error)
Can anyboby give a reason and solution to this problem...
Thanks in advance..
And also new to C/PYTHON API coding.
I am trying to have two way communication i,e i am calling from python to C and then from C to python.
I have no problem calling c func from python....
But problem is for calling C to Python
I am trying to call a python function multiple times by passing one parameter 'fun(param)' from C code .
I am getting segmentation fault error while executing .
The code i am is below...
# Python code..
import API # It is a shared library created by using 'Swig' Tool
class MyApp :
__init__(self, parent) # function to create GUI
//Code to create GUI.. (Text box)
API.function() ## here I am calling 'function()' (which is in 'call.c')
def fun(recv) :
//Here i am inserting the received(recv) value in GUI Text Widget.
return;
app = MyApp() //creating object to class 'MyApp'
// C code...
// call.c
function()
{
printf"Called from python\n"
call();
}
call()
{
while(first_tim e) {
Py_Initialise() ;
PyRun_SimpleStr ing("import pyfile"); //pyfile is my python file
}
PyRun_SimpleStr ing("pyfile.app .fun('SUCCESS') "); //fun is function inside pyfile and I am passing 'SUCCESS' as the parameter
// Py_Finalize();
}
To be more specific i am calling PyRun_SimpleStr ing("pyfile.fun ('SUCCESS')")
multiple times , initializing and importing only once...And Finalizing in the end .(If i initialize and finalize everytime i invoke the function i got segmentation fault error)
Can anyboby give a reason and solution to this problem...
Thanks in advance..
Comment