I believe that my
console-less py2exe-generated wxPython and PythonCard standalones are crashing
because of unhandled FutureWarnings(explanation below). Does anyone know if/how
FutureWarnings would/would not be handled in a console-less py2exe-generated wxPython
and PythonCard standalones?
I recently added some eval
and execfile calls at the top of some of my apps to allow the dynamic
evaluation of constants contained in an external file provided in its
distribution. The resulting apps ran wonderfully under python.exe, pythonw.exe,
and even the console version of the py2exe app. But the console-less version of
the py2exe app crashes.
It turned out that the
problem was that one of the statements I was evaluating generated an unhandled
FutureWarning. Each eval is inside a try/except block, but I was only
attempting to catch exceptions.StandardError. When I remove the line that was
generating the FutureWarning, the console-less version of the py2exe app works
fine. This behaviour can be reproduced by sticking:
eval(compile(“x=0xffffffff”,"",“single”)) into
the top of any wxPython or PythonCard app and building it into a console-less
standalone.
Presumably, these warnings
are what caused my console-less py2exe app crash. So, a couple questions:
-
Why would FutureWarnings
be treated so fatal in a console-less py2exe app? In the console py2exe app,
the FutureWarning is just printed to the console and the app proceeds happily. -
I would like to make my
dynamic code execution more robust to these warnings, but I have not been able
to successfully catch them. I can see that FutureWarning is in the built-in
namespace as well as in the exceptions module, but when I
try:
eval(compile("x=0xffffffff","","single"))
except FutureWarning:
print "caught
it!"
OR
try:
eval(compile("x=0xffffffff","","single"))
except
exceptions.FutureWarning:
print "caught
it!"
, the warning is not caught.
This might be a more general Python question, but how does one catch and/or
ignore FutureWarnings?
Thanks,
Tim