473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Problem with "PyRun_SimpleString" while interfacing Python with C

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_time) {
Py_Initialise();
PyRun_SimpleString("import pyfile"); //pyfile is my python file
}
PyRun_SimpleString("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_SimpleString("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..
Jul 24 '07 #1
3 6347
missinglinq
3,532 Expert 2GB
Welcome to TheScripts! You have inadvertantly posted your question in the MS Access Forum! We have both Python and C/C++ forums here, but since you indicate that your problem is calling Python from C, I'm moving your post to the C/C++ forum!

Linq ;0)>
Jul 24 '07 #2
Silent1Mezzo
208 100+
Expand|Select|Wrap|Line Numbers
  1. while(first_time) {
  2. Py_Initialise();
  3. PyRun_SimpleString("import pyfile"); //pyfile is my python file
  4. }
This is an infinite loop. Need to set first_time to something other than 1 after you run
Expand|Select|Wrap|Line Numbers
  1. PyRun_SimpleString("import pyfile");
This probably won't fix it but its something you should do.
Jul 24 '07 #3
This is an infinite loop. Need to set first_time to something other than 1 after you run
Expand|Select|Wrap|Line Numbers
  1. PyRun_SimpleString("import pyfile");
This probably won't fix it but its something you should do.
No actually actually i have declared first time as, static int first_time=0. And I am incrementing it inside the loop. But still I am grtting the problem.
Jul 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: disgracelands | last post by:
I've been looking at using python and it's been going fairly well so far, i can call C from python and python from C fine but now i've hit a snag and i'm wondering how you guys have got around it....
3
by: Link | last post by:
Dear sir, I am used to developing C program on MSVC7.0 platform. This is my first time to use Python for calling by C program. Now, it is hard to deal with the problem about extracting the...
3
by: Bill Orcutt | last post by:
Having seen the number of lost souls asking questions about embedding Python in the archives of this group, I hesitate to add myself to their number, but I've hit a problem I can't quite get my...
5
by: eq | last post by:
Hi, I'm trying to create a program(written in C) that does the following things using embedded Python: 1. Create a module(say, "MyModule") 2. Create a class in that module(say, "MyClass") 3....
2
by: Ugo Di Girolamo | last post by:
I have the following code, that seems to make sense to me. However, it crashes about 1/3 of the times. My platform is Python 2.4.1 on WXP (I tried the release version from the msi and...
1
by: freesteel | last post by:
I have posted about this problem before. SInce then I found a much better article to help with embedding python in a multithreaded application: http://www.linuxjournal.com/article/3641 I...
2
Bulldog
by: Bulldog | last post by:
I am new to this board and I am using Python 2.2.1 on Windows XP SP2. I am working on embedding some python functionality in a C++ win32 DLL, and I am having issues using the PyImport_ functions...
3
by: Jim Hill | last post by:
Well, I've found about a hundred thousand web pages where people have had the same problem I have but nary a page with a solution that works for me. I want to do a simple embed, so I've followed...
4
by: Chris8Boyd | last post by:
I am embedding Python in a MSVC++ (2005) application. The application creates some environment and then launches a Python script that will call some functions exported from the MSVC++ application....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.