Vlastimil Brom wrote:
Hi all,
I'd like to ask for advice regarding the usage of excepthook in
wx.phoenix;
in my app, which I am trying to port from py27 + wxpython classic to
py3.4 + phoenix, I am using sys.excepthook for displaying remaining
errors in a dialog, as I prefer all messages to stay within the gui.
The hook function is simply displaying the error data in a message
dialog.
The problem I am facing regards the PyShell part of my app - for code
run form this shell, I need the error message and trace to be shown in
the shell itself as usual, but in phoenix (3.0.3.dev1641+76cf834 msw
(phoenix) + py 3.4.2) my excepthook somehow overrides this and the
errors are shown in the dialogs too.
In classic wxpython 3.0.0.0 msw (classic) + py 2.7.6 this works as
expected without any extra effort.
(In both versions I use win 7, 32-bit python versions).
Is it possible to get the behaviour in classic? Or is it possibly some
bug in PyShell or some other issue?
Thanks in advance,
vbr
Hi all,
I'd like to attach a simplified sample app demonstrating the mentioned
problems, in case my original description wasn't clear. The code
behaves differently between python versions and wx implementations, as
mentioned in the comment:
TBH, I'm not sure why this works in any Python. sys.execpthook is called
when an exception is not caught, and I thought that PyShell doesn't actually
catch the exceptions but just captures the printing of the tracebacks to
sys.stderr. It's been a long time since I dug into that code however so I
could be misremembering things.
Anyway, it sounds like there needs to be a modification made to PyShell
where it clears sys.excepthook before running the code, and restores it
after. I'll gladly review a patch that does that if you or anybody else
submits one.
--
Robin Dunn
Software Craftsman
http://wxPython.org
--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for the hint, Robin,
it appears, that the origin of this difference is in the python
standard library, outside of wxpython - I hadn't looked that far
before in my previous debuging attempts.
In python 3.4 the excepthook is explicitly handled and called in code.py
C:\Python34\Lib\code.py
def showtraceback(self):
[...]
finally:
tblist = tb = None
if sys.excepthook is sys.__excepthook__:
self.write(''.join(lines))
else:
# If someone has set sys.excepthook, we let that take precedence
# over self.write
sys.excepthook(type, value, tb)
which wasn't the case in python 2.7:
C:\Python27\Lib\code.py
def showtraceback(self):
[...]
finally:
tblist = tb = None
map(self.write, list)
Unless I missed some problems or cornercases, it seems, that the
problem can be worked around with the following hack - a special case
in the excepthook function:
def redirect_error(err_type, err_value, err_trace):
if "wx\\py\\interpreter.py" in "".join(traceback.format_stack()):
# bypass pyshell - TEST!!
sys.__excepthook__(err_type, err_value, err_trace)
return False
...
the only difference I noticed is another item in the traceback, code.py ...
1/0 # pyshell using redirect_error excethook
Traceback (most recent call last):
File "C:\Python34\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
ZeroDivisionError: division by zero
1/0 # pyshell without excethook
Traceback (most recent call last):
File "<input>", line 1, in <module>
ZeroDivisionError: division by zero
Anyway, unless some other problems arise, I am quite happy with the
current solution. I'd be grateful for ideas of other possible
approaches.
thanks and regards,
vbr
···
2015-03-07 2:32 GMT+01:00 Robin Dunn <robin@alldunn.com>:
2015-02-12 0:43 GMT+01:00 Vlastimil Brom<vlastimil.brom@gmail.com>: