473,657 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error on crude test of embedding python in c++ HELP PLEASE

I wrote a program to test calling c function from python code embedding in c
as following, it cause error after running a while(about 398 circle). I
test it in msvc6, python2.3, windows 2k, could anyone tell me why this
happened since i just work according to the document? Thanks first.

Donnie Leen
source code:
#include <Python.h>

static PyObject* pymyfun( PyObject* self, PyObject* args )
{
return Py_None; // do nothing
}
static PyMethodDef emb_methods[] = {
{ "fun", pymyfun, METH_VARARGS, "doc." },
{NULL, NULL, 0, NULL}
};

void main( )
{
Py_Initialize( );

PyObject* r = Py_InitModule( "mymodule", emb_methods );
PyRun_SimpleStr ing( "import mymodule" );
while ( 1 )
{
// error occur after 398 loops here
PyRun_SimpleStr ing( "mymodule.f un( 'testest' )" );
}

Py_Finalize();
}

Jul 18 '05 #1
2 1393
"Donnie Leen" <Ki*********@ye ah.net> writes:
I wrote a program to test calling c function from python code embedding in c
as following, it cause error after running a while(about 398 circle). I
test it in msvc6, python2.3, windows 2k, could anyone tell me why this
happened since i just work according to the document? Thanks first.

Donnie Leen
source code:
#include <Python.h>

static PyObject* pymyfun( PyObject* self, PyObject* args )
{
return Py_None; // do nothing
You forgot an Py_INCREF here:
Py_INCREF(Py_No ne);
return Py_None; // do nothing
}
static PyMethodDef emb_methods[] = {
{ "fun", pymyfun, METH_VARARGS, "doc." },
{NULL, NULL, 0, NULL}
};

void main( )
{
Py_Initialize( );

PyObject* r = Py_InitModule( "mymodule", emb_methods );
PyRun_SimpleStr ing( "import mymodule" );
while ( 1 )
{
// error occur after 398 loops here
PyRun_SimpleStr ing( "mymodule.f un( 'testest' )" );
}

Py_Finalize();
}

Jul 18 '05 #2
Got it, thanks :)

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2775
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been working with Python for a year or more now, but only doing simple extending in C/C++. I'm now attempting some embedding and several questions have come to mind. BTW - I'm running Windows 2000 with Python23 and VisualC++ developers
0
1327
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). Can anyone clarify: - if Python correctly supports multiple sub-interpreters (Py_NewInterpreter) ?
2
1982
by: John Dean | last post by:
Hi Could somebody, please tell me where I can find information about embedding Python into a C/C++ application. The example in the docs is rather simple. I am looking for something a bit more complex and longer -- Best Regards John
6
2996
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python interface is providing a convenient scripting toolkit for the application. One example is that a user can write a python script like: player = Player() game.loadPlayer(player) player.moveTo(location)
4
324
by: | last post by:
Hi, Today is my first day of working on python. I want to execute python script through C++ program. I found one very good article with example at http://docs.python.org/ext/pure-embedding.html. I followed the procedure as given, the code is compiled but while running it is giving error like: ImportError: No module named multiply Failed to load "multiply"
1
1722
by: could.net | last post by:
I use boost 1.33_1, there's an example on boost::python named embedding.cpp. When I tried to build and run it in visual studio 2005, I got an error on this line: std::string hello() { return python::call_method<std::string>(self, "hello"); } It's a back ptr error. I don't know where to ask this question so I came to python group. Has
2
5317
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
1
1499
by: Eric_Dexter | last post by:
I compiled the comand line example and I am getting an error when I try to use the program when the program is cleaning up (I don't know that it would prevent the program from running though I will run more tests)... ebedpython test testt result of call: -1 exception exceptions.TypeError: 'an integer is required' in ' 'garbage collection' ignored Fatal Python error: unexpected exception during garbage collection... the program is just
6
1052
towsie
by: towsie | last post by:
Hi, I would be very grateful if someone could have a look at the staement below and help me find the Syntax Error. ("Select origin_of_sale as Origin, Category, Crude.F3 as Customer, sales_terms, autolift, load_point as lp, Crude.F11 as Vessel, Crude.F2 as CONTRACT_NO, VALUE_ONLY, invoice_unit, Ledger_unit, Contract_date, template_name, acct_to_group_conversion as conv, Crude.F5, Crude.F6 as quantity, Crude.F8 as tax_quantity, Crude.F1 as...
0
8315
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,...
0
8829
Oralloy
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...
1
8508
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,...
0
8608
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 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...
0
7341
agi2029
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...
0
4164
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...
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
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...

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.