Problem flushing stderr in embedded python

Farshid Lashkari lashkariNO at SPAMworldviz.com
Thu Nov 11 13:51:03 EST 2004


Well I've somewhat solved my problem. First off, the 'y' problem was just an
error I purposely created in order to trigger an exception. My application
uses a bunch of calls to PyObject_Call to run python code. After each of
these calls I added:

if(PyErr_Occurred()) PyErr_Print();

This will force the errors to be printed to stderr, and now calling the
flush method on the stderr object works. I still don't understand why
running the string "sys.stderr.flush()" is different. Maybe it forces any
current errors to be printed and then flushes them too. My app doesn't
replace the python stderr object either.

Anyways, thanks to everybody for your help and suggestions.

-Farshid

"Donn Cave" <donn at drizzle.com> wrote in message
news:1100156058.567069 at yasure...
> Quoth "Farshid Lashkari" <lashkariNO at SPAMworldviz.com>:
> ...
> | I've tried calling fflush on stderr, but that doesn't work either.
>
> OK, this would seem to mean that your sys.stderr has been replaced
> with something else.  I guess I don't know for sure what you can
> count on in Windows, but I would have to expect that fflush on stderr
> really does work - that is, it flushes stderr's buffer.
>
> | I've encountered another weird problem also. If my python code causes an
> | error and I don't flush stderr, then I get a runtime error when my app
> | exits. It also prints out:
> |
> | Exception exceptions.NameError: "global name 'y' is not defined" in
'garbage
> | collection' ignored
> | Fatal Python error: unexpected exception during garbage collection.
> |
> | Does this give anybody a clue as to what's happening?
>
> Doesn't do anything for me, but you may find out what that is when you
> locate the code for the faux stderr you're (not) flushing.  I would be
> more worried about this 'y' thing in principle, though, because it sounds
> like a problem in the C (or whatever) to Python interface that could have
> other unpleasant consequences.
>
> Donn Cave, donn at drizzle.com





More information about the Python-list mailing list