Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: retrieve traceback in embedded python of Python3.0?

Reply
Thread Tools

Re: retrieve traceback in embedded python of Python3.0?

 
 
BigHand
Guest
Posts: n/a
 
      03-07-2009
On Mar 7, 11:40*am, BigHand <(E-Mail Removed)> wrote:
> Guys:
> I have a embedded python in MFC app. to execute a py script of a.py,
> the is only one line in a.py, it "a()" , normally ,excute this script
> file ,you will get a
> *"the exception type is<class 'NameError'> "
> "The exception value is name 'a' is not defined "
>
> Python3.0 with VS2005.
> here is the brief code:
> Py_Initialize();
> PyObject *m, *d, *v;
> m = PyImport_AddModule("__main__");
> d = PyModule_GetDict(m);
> v = PyRun_File(fp, pStr, Py_file_input, d, d); * * * //~~~the py
> script is a.py
> PyObject *exc_type = NULL, *exc_value = NULL, *exc_tb = NULL;
> PyErr_Fetch(&exc_type, &exc_value, &exc_tb); *//~~~after fetch , the
> exc_type, exc_value, exc_tb are not "NULL"
> PyObject * modTB = PyImport_ImportModule("traceback");
> PyObject* pyUStr = PyUnicode_FromString("format_exception");
> PyObject* listTB = PyObject_CallMethodObjArgs(modTB, *pyUStr,
> exc_type, exc_value, exc_tb, NULL);
>
> in the PyObject_CallMethodObjArgs(modTB, *pyUStr, exc_type, exc_value,
> exc_tb, NULL), I get modTB, pyUStr, exc_type, exc_value, exc_tb are
> not NULL, but the listTB is always NULL, I can retrieve the list...
>
> any body could enlight me?


it's "I can't retrieve the traceback list."
 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      03-07-2009
En Sat, 07 Mar 2009 01:43:05 -0200, BigHand <(E-Mail Removed)> escribió:
> On Mar 7, 11:40*am, BigHand <(E-Mail Removed)> wrote:
>> Guys:
>> I have a embedded python in MFC app. to execute a py script of a.py,
>> the is only one line in a.py, it "a()" , normally ,excute this script
>> file ,you will get a
>> *"the exception type is<class 'NameError'> "
>> "The exception value is name 'a' is not defined "
>>
>> Python3.0 with VS2005.
>> here is the brief code:
>> Py_Initialize();
>> PyObject *m, *d, *v;
>> m = PyImport_AddModule("__main__");
>> d = PyModule_GetDict(m);
>> v = PyRun_File(fp, pStr, Py_file_input, d, d); * * * //~~~the py
>> script is a.py
>> PyObject *exc_type = NULL, *exc_value = NULL, *exc_tb = NULL;
>> PyErr_Fetch(&exc_type, &exc_value, &exc_tb); *//~~~after fetch , the
>> exc_type, exc_value, exc_tb are not "NULL"
>> PyObject * modTB = PyImport_ImportModule("traceback");
>> PyObject* pyUStr = PyUnicode_FromString("format_exception");
>> PyObject* listTB = PyObject_CallMethodObjArgs(modTB, *pyUStr,
>> exc_type, exc_value, exc_tb, NULL);
>>
>> in the PyObject_CallMethodObjArgs(modTB, *pyUStr, exc_type, exc_value,
>> exc_tb, NULL), I get modTB, pyUStr, exc_type, exc_value, exc_tb are
>> not NULL, but the listTB is always NULL, I can retrieve the list...
>>
>> any body could enlight me?

>
> it's "I can't retrieve the traceback list."


PyErr_Print or PyTraceback_Print aren't suitable for you? Those functions
are much easier to use from C code, while the traceback module is intended
to be used in Python code.

--
Gabriel Genellina

 
Reply With Quote
 
 
 
 
BigHand
Guest
Posts: n/a
 
      03-09-2009
On Mar 7, 9:22*pm, "Gabriel Genellina" <(E-Mail Removed)> wrote:
> En Sat, 07 Mar 2009 01:43:05 -0200, BigHand <(E-Mail Removed)> escribió:
>
>
>
> > On Mar 7, 11:40*am, BigHand <(E-Mail Removed)> wrote:
> >> Guys:
> >> I have a embedded python in MFC app. to execute a py script of a.py,
> >> the is only one line in a.py, it "a()" , normally ,excute this script
> >> file ,you will get a
> >> *"the exception type is<class 'NameError'> "
> >> "The exception value is name 'a' is not defined "

>
> >> Python3.0 with VS2005.
> >> here is the brief code:
> >> Py_Initialize();
> >> PyObject *m, *d, *v;
> >> m = PyImport_AddModule("__main__");
> >> d = PyModule_GetDict(m);
> >> v = PyRun_File(fp, pStr, Py_file_input, d, d); * * * //~~~the py
> >> script is a.py
> >> PyObject *exc_type = NULL, *exc_value = NULL, *exc_tb = NULL;
> >> PyErr_Fetch(&exc_type, &exc_value, &exc_tb); *//~~~after fetch , the
> >> exc_type, exc_value, exc_tb are not "NULL"
> >> PyObject * modTB = PyImport_ImportModule("traceback");
> >> PyObject* pyUStr = PyUnicode_FromString("format_exception");
> >> PyObject* listTB = PyObject_CallMethodObjArgs(modTB, *pyUStr,
> >> exc_type, exc_value, exc_tb, NULL);

>
> >> in the PyObject_CallMethodObjArgs(modTB, *pyUStr, exc_type, exc_value,
> >> exc_tb, NULL), I get modTB, pyUStr, exc_type, exc_value, exc_tb are
> >> not NULL, but the listTB is always NULL, I can retrieve the list...

>
> >> any body could enlight me?

>
> > it's "I can't retrieve the traceback list."

>
> PyErr_Print or PyTraceback_Print aren't suitable for you? Those functions
> are much easier to use from C code, while the traceback module is intended
> to be used in Python code.
>
> --
> Gabriel Genellina


Hello,Gabriel,

I gave up using the format_exception, and use calling the python
fucntion of print_tb.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"raise (type, value, traceback)" and "raise type, value, traceback" Jack Bates Python 0 05-02-2011 05:23 PM
retrieve traceback in embedded python of Python3.0? BigHand Python 0 03-07-2009 03:40 AM
traceback from embedded python Skink Python 0 09-17-2005 03:16 PM
Using Python traceback info from C/C++. Duncan Booth Python 1 07-12-2004 10:04 AM
>>> python test1.py / Traceback ( File "<interactive input>", line 1 leroybt.rm Python 2 11-26-2003 01:35 AM



Advertisments