This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: strange thing after call PyObject_CallMethod
Type: behavior Stage:
Components: Documentation Versions: Python 3.0, Python 3.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: amaury.forgeotdarc, exe, georg.brandl
Priority: normal Keywords:

Created on 2009-01-29 11:42 by exe, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg80757 - (view) Author: Kandalintsev Alexandre (exe) Date: 2009-01-29 11:42
When unhandled in python code exception occurs in PyObject_CallMethod 
frame_dealloc() (Objects/frameobject.c:422) 
not called. Even if I call PyErr_Print(). 

But if I call PyErr_Clear() then all okay. Documentation says that both 
this functions doing same work(http://docs.python.org/3.0/c-api/
exceptions.html). As we see thats not true or not all nuances documented.

Examples and more on this mailing list:
http://groups.google.com/group/comp.lang.python/browse_thread/
thread/19316b3effa37d2d
msg80759 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-01-29 12:06
I think I have an explanation:
When a python exception is raised, the current call stack is stored in
the exception state (tstate->curexc_traceback). This includes all the
living frame objects, with all their local variables.
This explains why frame_dealloc is not called at this time, and why the
"self" object has its refcount increased.

PyErr_Clear() releases everything.
PyErr_Print() does clear tstate->curexc_traceback, but only to copy the
value into sys.last_traceback; So the frame object is still alive.

I suggest you to use PyErr_PrintEx(0), which will print and clear the
error, but not store the exception info into the sys.last_* variables.
[PyErr_Print() simply calls PyErr_PrintEx(1); No, it's not yet documented]
msg80761 - (view) Author: Kandalintsev Alexandre (exe) Date: 2009-01-29 12:50
Thank you for your activity. This feature drank alot of my blood. Please 
document this or change behavior.

PS Older python versions may be also affected so changing behavior may 
brake existing code :(
msg81199 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-02-05 10:56
Documented PyErr_PrintEx() in r69292.
History
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49346
2009-02-05 10:56:52georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg81199
2009-01-29 13:16:23amaury.forgeotdarcsetassignee: georg.brandl
components: + Documentation, - Interpreter Core
nosy: + georg.brandl
2009-01-29 12:50:53exesetmessages: + msg80761
2009-01-29 12:06:30amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg80759
2009-01-29 11:42:54execreate