Re: Having to "print" before method invocation?



Jeremy L. Moles wrote:

I have an object (written as part C extension, part pure Python) called
foo that I've been using without much fuss for a few months now.
However, in my latest project (a rather large one involving
multi-threading, pygtk, etc.), I'm seeing some really strange behavior
with a particular instance of my foo object.

About midway through my program, any attempt to use the instance fails;
however, if I add print statements before trying to invoke methods on
it, the foo object instance works fine.

fails in what way?

if you get a spurious exception, it's very likely that your C extension sets the
exception state (either directly or because some API function it uses fails), but
forgets to report this back to Python.

e.g. if you have a C function that does something like

PyErr_SetString(PyExc_AttributeError, "blah blah"):

Py_INCREF(Py_None);
return Py_None;

instead of

PyErr_SetString(PyExc_AttributeError, "blah blah"):

return NULL;

the interpreter won't raise the exception immediately (since it expected you to
return NULL if something went wrong), but the exception may still be raised at
a later time, if you run interpreter code that does something like

do something
if (PyErr_Occurred())
... /* this will catch your error even if "something" succeeds */ ...

*or* it may be masked, by code that does

PyErr_Clear();
do something

the actual exception might give you additional clues (e.g. if you get a KeyError,
look for unchecked dictionary accesses in your code, etc).

hope this helps!

</F>



.



Relevant Pages

  • Re: Threading and Serial port issue
    ... "fails" is pretty useless information. ... If it generates an exception, ... I then sit in a loop waiting for data to arrive. ... private void SetupBoard_Click ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Strange error when app starts
    ... installed correctly via the installer ... machines and until recently they all worked perfectly. ... updated the application to a new version one of the machines fails ... unhandled exception when the application starts. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Coding inside the debugger
    ... but why isn't the test written so that the reason it fails is ... If something fails in tests like these, ... public void testCreateWithDefaultthrows Exception { ... Ghostworld world = worldWithClass; ...
    (comp.object)
  • Could not load file or assembly every few days - asp.net 1.1
    ... Could not load file or assembly 'Foo, Version=1.0.2388.18427, ... An unhandled exception occurred during the execution of the ... Please review the stack trace for more information about ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Having to "print" before method invocation?
    ... Hey Fredrik, thanks for responding. ... foo that I've been using without much fuss for a few months now. ... if I add print statements before trying to invoke methods on ... the interpreter won't raise the exception immediately (since it expected you to ...
    (comp.lang.python)