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..
3 6403
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)> - while(first_time) {
-
Py_Initialise();
-
PyRun_SimpleString("import pyfile"); //pyfile is my python file
-
}
This is an infinite loop. Need to set first_time to something other than 1 after you run - PyRun_SimpleString("import pyfile");
This probably won't fix it but its something you should do.
This is an infinite loop. Need to set first_time to something other than 1 after you run - 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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
I have to initialise python inside my C project so that i can make calls to
python modules whenever i need to but i can't create a dll for the project
as it's got to produce an exe or at least a lib so that i can execute the
initialisation...
|
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 variable
which be definied in Python. That how can I do?
I have gotten the JPython 's sample that the following code can be looked.
Have anyone help me to obtain same results that be called by Python's C API?
What do I mean?
|
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 head around.
I have a simple C program that embeds a python interpreter to execute
python commands and return stdout, and to a point everything works as
intended. The problem that each command seems to be executed in its
own context and knows...
|
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. Create a function in that module(say, "MyFunction")
The Python-code would look like this:
MyClass.py:
|
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 the debug version built by me, both downloaded today to
have the latest version).
| |
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 found this article very good and it clarified for me what needs
doing. Now I have an example application that almost works, but it is
far from reliable. If I run this several times I get crashes telling me
that the heap is modified after deallocation....
|
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 available in the python C API. More specifically I am trying to use Pyimport_ImportModule() to import sys, and it doesn't work. I have also tried using PyString_FromString() to convert the the string "sys" to a Python object to then use...
|
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 the example in the
Extending and Embedding documentation:
In the .c file,
#include <Python.h>
|
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.
I want to be able to debug the Python script by using a debug server,
like Winpdb (winpdb.org).
I use ActivePython 2.5.2.2, Microsoft Visual Studio 2005, and Winpdb
1.3.8.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |