using python interpreters per thread in C++ program

2009-09-06 Thread grbgooglefan
Hi I've a multi-threaded C++ program, in which I want to use embedded python interpreter for each thread. I am using Python 2.6.2 on Linux for this. When I tried to embed python interpreter per thread, I got crash when the threads were calling Python's C APIs. Can we not use python interpreters

Python interpreters in threads crash the application

2009-04-15 Thread grbgooglefan
I have C application in which I have instantiated Python interpreter in each worker thread. When I start the program it crashes at different places in Python code but program never finishes normally. One such core dump is given below. Can you please help me in following queries? 1) Can we not us

building release - assert-free python library

2009-04-07 Thread grbgooglefan
How can I build a release and not the debug version of libpython.a? I have seen that there are assert, abort statements in lot many functions in Python code. I would like to avoid those when compiling the libpython.a library because when this libpython gets used for production purpose and it aborts

Re: How to free /destroy object created by PyTuple_New

2009-04-05 Thread grbgooglefan
Regarding PyTuple_New, when I pass this tuple with variable values set to some evaluation function like PyObject_CallObject, do I need to increment reference for this tuple & then decrement again after the call returns? If I've not configured my libpython with threads when compiling, will PyGILSta

Re: How to free /destroy object created by PyTuple_New

2009-04-04 Thread grbgooglefan
On Apr 4, 10:27 pm, Andrew Svetlov wrote: > To destroy every python object you need to call Py_DECREF. > To call python code fron you C thread you need to use pair > PyGILState_Ensure/PyGILState_Release. In my case, my C application has multiple threads & they are accessing a single Python Interp

How to free /destroy object created by PyTuple_New

2009-04-04 Thread grbgooglefan
I am using PyTuple_New to pass function arguments to PyObject_CallObject for execution of a Python function. How can I free up the memory and object allocated by the PyTuple_New function? I am using Python interpreter in my multi-threaded C application & at load condition my application crashes

Call to PyEval_EvalCodeEx crashes in PyFrame_New with abort

2009-03-30 Thread grbgooglefan
I've emabedded Python(2.6) in my C++ application and using on Solaris 5.10. When the application calls Py_Eval, it causes an abort & application core dumps. But this is at random times & no pattern for this. Crash is as below: Can you please help to know, what can cause this abort in PyFrame_New?

How to modify meaning of builtin function "not" to "!"?

2008-05-09 Thread grbgooglefan
I am creating functions, the return result of which I am using to make decisions in combined expressions. In some expressions, I would like to inverse the return result of function. E.g. function contains(source,search) will return true if "search" string is found in source string. I want to make

Re: how to pass C++ object to another C++ function via Python function

2008-05-09 Thread grbgooglefan
Yes, that worked. I "protected" the variable which I did not want to get freed. I incremented reference for that variable & it started working. Thanks for all your guidance. On May 3, 5:23 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > Python will do nothing with the pointer inside a PyCObj

Re: how to pass C++ object to another C++ function via Python function

2008-05-01 Thread grbgooglefan
On Apr 22, 7:54 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > > If you have a C function that receives a PyCObject, just include the   > relevant headers (cobject.h) and you can retrieve the original pointer   > using PyCObject_AsVoidPtr: > > void foo(PyObject *pyobj) > { >    TOriginalType

Re: how to pass C++ object to another C++ function via Python function

2008-04-21 Thread grbgooglefan
On Apr 21, 10:17 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 21 Apr 2008 10:24:15 -0300, grbgooglefan <[EMAIL PROTECTED]> escribió: > > > I am trying to pass a C++ object to Python function. This Python > > function then calls ano

how to pass C++ object to another C++ function via Python function

2008-04-21 Thread grbgooglefan
I am trying to pass a C++ object to Python function. This Python function then calls another C++ function which then uses this C++ object to call methods of that object's class. I tried something like this, but it did not work, gave core dump. class myclass { public: myclass(){};

is hash map data structure available in Python?

2008-03-19 Thread grbgooglefan
Hi, I have a situation that I need to search a name in a big list of names in my Python embedded interpreter. I am planning to use hash map for quicker search. How do I create hash map in Python? Can you please guide me to some documentation or tutorial which provides information on creating, editi

Re: PyImport_ImportModule("cStringIO") failure with undefined symbol

2008-01-31 Thread grbgooglefan
On Jan 11, 9:31 am, "Borse, Ganesh" <[EMAIL PROTECTED]> wrote: > Hi, > Can you please guide me for the following problem? > The call to "PyImport_ImportModule("cStringIO");" is failing with an error of > "undefined symbol:PyObject_SelfIter". > > Before importing this module, I am importing only th

Re: Import of cStringIO failing with "undefined symbol: PyObject_SelfIter" on python-2.3.3-88.9

2008-01-31 Thread grbgooglefan
On Jan 10, 6:07 pm, grbgooglefan <[EMAIL PROTECTED]> wrote: > I am importing cStringIO module in my PythonC++ embedded program. > > The import is failing with the following error: > ImportError: /usr/lib/python2.3/lib-dynload/cStringIO.so: undefined > symbol:PyObject_SelfI

Re: how to get string printed by PyErr_Print( )?

2008-01-31 Thread grbgooglefan
On Jan 9, 8:01 pm, grbgooglefan <[EMAIL PROTECTED]> wrote: > On Dec 19 2007, 5:55 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > >grbgooglefanwrote: > > > PythonC API functionPyErr_Print( ) prints an error string onto stderr > > > if PyErr_Occurred() is tr

Re: Replacing call to PyObject_CallObject with PyEval_CallFunction

2008-01-29 Thread grbgooglefan
On Jan 30, 1:58 pm, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > On 30 ene, 01:58, grbgooglefan <[EMAIL PROTECTED]> wrote: > > > How do I pass the elements populated in struct variables of this > > vector dynamically to PyEval_CallFunction, in the f

Replacing call to PyObject_CallObject with PyEval_CallFunction

2008-01-29 Thread grbgooglefan
Hello Python Experts May you please help me on this change? I have following code: //== typedef struct IOParams { char *ioString; long lionum; double dionum; float fionum; intnionum; } *pIOParams; //

Re: how to set sys.stderr to object of cStringIO type

2008-01-15 Thread grbgooglefan
On Jan 15, 5:45 pm, grbgooglefan <[EMAIL PROTECTED]> wrote: > I am in a perculiar situation. I want to use PyRun_SimpleString for > creating Python functions in embedded Python in C++. > But there could be cases when Python function code compilation could > fail & PyRun_Simpl

[help request] how to set sys.stderr to object of cStringIO type

2008-01-15 Thread grbgooglefan
I am in a perculiar situation. I want to use PyRun_SimpleString for creating Python functions in embedded Python in C++. But there could be cases when Python function code compilation could fail & PyRun_SimpleString will return -1 as return status. At this time, it prints the error message to sys.s

Import of cStringIO failing with "undefined symbol: PyObject_SelfIter" on python-2.3.3-88.9

2008-01-10 Thread grbgooglefan
I am importing cStringIO module in my PythonC++ embedded program. The import is failing with the following error: ImportError: /usr/lib/python2.3/lib-dynload/cStringIO.so: undefined symbol: PyObject_SelfIter I have python-2.3.3-88.9.x86 installed on my machine. Why is this error coming? how can I

Re: how to get string printed by PyErr_Print( )?

2008-01-09 Thread grbgooglefan
On Dec 19 2007, 5:55 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > grbgooglefan wrote: > > PythonC API functionPyErr_Print( ) prints an error string onto stderr > > if PyErr_Occurred() is true. > > I don't want to print this to stderr because my Python+C code is

Python modules - how to create & which are better

2008-01-08 Thread grbgooglefan
I have embedded Python in my C++ application & creating Python function from the expression. I am then evaluating those Python compiled function (byte code) using PyObject_CallObject. I want to create a Python module which will have functions called by my user defined functions from the embedded P

Re: PyObject_CallObject code dump after calling 4 times

2008-01-03 Thread grbgooglefan
On Jan 3, 8:49 pm, grbgooglefan <[EMAIL PROTECTED]> wrote: > On Jan 3, 8:02 pm, Phil Thompson <[EMAIL PROTECTED]> > wrote: > > > > > > > On Thursday 03 January 2008, grbgooglefan wrote: > > > > I have a following C++ code which uses PyObject_C

Re: PyObject_CallObject code dump after calling 4 times

2008-01-03 Thread grbgooglefan
On Jan 3, 8:02 pm, Phil Thompson <[EMAIL PROTECTED]> wrote: > On Thursday 03 January 2008, grbgooglefan wrote: > > > I have a following C++ code which uses PyObject_CallObject to evaluate > > expressions dynamically. This code sets the input parameters for the > > fu

PyObject_CallObject code dump after calling 4 times

2008-01-03 Thread grbgooglefan
I have a following C++ code which uses PyObject_CallObject to evaluate expressions dynamically. This code sets the input parameters for the function also dynamically. After calling this function 4 times (with these shown values), PyObject_CallObject causes application to crash in frame_dealloc. 1)

how to get string printed by PyErr_Print( )?

2007-12-19 Thread grbgooglefan
PythonC API function PyErr_Print( ) prints an error string onto stderr if PyErr_Occurred() is true. I don't want to print this to stderr because my Python+C code is running daemon mode & won't have terminal / stderr. So, I want to retrieve the string which PyErr_Print( ) will print. E.g., PyErr_Pri

releasing the reference returned by PyLong_FromLong, PyString_FromString & friends

2007-12-13 Thread grbgooglefan
I am having a object tuple created at application startup. This tuple I pass on to a python function in call to: PyObject_CallObject(pcatInfo->pPyEvalFunction,pTuple); For setting the values in this tuple, I am using PyLong_FromLong, PyString_FromString & friends functions. PyTuple_SetItem(pTu

Re: Erros when compiling a CPP program which uses CPython API functions

2007-12-07 Thread grbgooglefan
On Dec 7, 5:15 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > grbgooglefan wrote: > > I am compiling CPP program which uses CPython API functions from > > Python 2.5.1 source code > > > First I compiled with this commanline, that time I got "pyconfig.h"

Re: Erros when compiling a CPP program which uses CPython API functions

2007-12-07 Thread grbgooglefan
On Dec 7, 2:17 pm, grbgooglefan <[EMAIL PROTECTED]> wrote: > On Dec 7, 12:32 pm, grbgooglefan <[EMAIL PROTECTED]> wrote: > > > > > > > I am compiling CPP program which uses CPython API functions from > > Python 2.5.1 source code > > > Fir

Re: Can I embed Windows Python in C# or VC++?

2007-12-07 Thread grbgooglefan
On Dec 7, 3:07 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 07 Dec 2007 01:24:57 -0300, grbgooglefan <[EMAIL PROTECTED]> > escribió: > > > > > > > On Dec 7, 12:17 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > &g

Re: weird embedding problem

2007-12-07 Thread grbgooglefan
On Dec 7, 2:01 pm, DavidM <[EMAIL PROTECTED]> wrote: > Hi all, > > I'm embedding python in a C prog which is built as a linux shared lib. > > The prog is linked against libpython, and on startup, it calls > Py_Initialize(). > > The prog imports a pure-python script. The script starts up ok, but whe

Re: Erros when compiling a CPP program which uses CPython API functions

2007-12-06 Thread grbgooglefan
On Dec 7, 12:32 pm, grbgooglefan <[EMAIL PROTECTED]> wrote: > I am compiling CPP program which uses CPython API functions from > Python 2.5.1 source code > > First I compiled with this commanline, that time I got "pyconfig.h" > not found. > g++ -Os -I../../Inc

Erros when compiling a CPP program which uses CPython API functions

2007-12-06 Thread grbgooglefan
I am compiling CPP program which uses CPython API functions from Python 2.5.1 source code First I compiled with this commanline, that time I got "pyconfig.h" not found. g++ -Os -I../../Include ../../libpython2.5.a -lm -ldl -lpthread -lutil testeval.cpp In file included from testeval.cpp:1: ../../I

Re: Can I embed Windows Python in C# or VC++?

2007-12-06 Thread grbgooglefan
On Dec 7, 12:17 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 06 Dec 2007 23:27:15 -0300, grbgooglefan <[EMAIL PROTECTED]> > escribió: > > > I want to use Python's Windows (python25.dll) version to embed in my > > C# (or atleast V

Can I embed Windows Python in C# or VC++?

2007-12-06 Thread grbgooglefan
I want to use Python's Windows (python25.dll) version to embed in my C# (or atleast VC++) program for performing syntax checks on the Python expressions which are later supposed to be evaluated at runtime by another C++ program For this, I would like to use CPython API functions such as Py_Initial

Re: Question on compiled code when embedding Python in C++

2007-12-03 Thread grbgooglefan
On Dec 4, 12:36 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Tue, 04 Dec 2007 00:54:57 -0300, Borse, Ganesh > <[EMAIL PROTECTED]> escribió: > > > When we compile a Python code using functions such as Py_CompileString > > or any other similar compile function, what will be the resulti

Re: What is the function to evaluate code object returned byPyParser _SimpleParseString function?

2007-11-21 Thread grbgooglefan
On Nov 16, 7:11 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Borse, Ganesh" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > | Py_CompileString takes the sourcecodefrom file, isn't it? > > No. > > | As can be seen from the syntax of thisfunction: "PyObject* > Py_CompileString(ch

[ Please help ] how to create Python functions in C++ at runtime & call them

2007-11-20 Thread grbgooglefan
I want to compile following type of python function in my C++ program at runtime. def isSizeSmall(size,vol,ADV,prod): if ( (size < 1000) & (vol < (0.001 * ADV)) & (prod=="Stock")): print "OK"; return 10 else: print "NOK"; return 11 Using Py_CompileString, I compiled a code object from this f