I'm having a bit of a problem with how Python3 is handling a specific Exception, which should be ignored, but that gets printed out anyway at the end of execution along with a Traceback.
Specifically, I use the graph-tool library to launch an interactive window, like so:
graph_tool.draw.interactive_window(self.graphtool_graph, vertex_text=self.v_label, vertex_font_size=6,geometry=(1920, 1080))
And my problem arises if I close the window that is opened before it finishes drawing and laying out the graph itself. Then, when execution of my code is finished, I get this printout:
Exception ignored in: <bound method GraphWindow.__del__ of <gtk_draw.GraphWindow object at 0x7f221ccf3750 (graph_tool+draw+gtk_draw+GraphWindow at 0x4c662a0)>>
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/graph_tool/draw/gtk_draw.py", line 1183, in __del__
File "/usr/lib/python3/dist-packages/graph_tool/draw/gtk_draw.py", line 375, in cleanup
File "/usr/lib/python3/dist-packages/gi/overrides/__init__.py", line 68, in __get__
TypeError: 'NoneType' object is not callable
Which is obviously not very nice to see, especially if it's an end user interacting with my project.
I tried to enclose the call to draw.interactive_window
in a try-catch statement, like so:
try:
graph_tool.draw.interactive_window(self.graphtool_graph, vertex_text=self.v_label, vertex_font_size=6,
geometry=(1920, 1080))
except TypeError:
# Interactive Window closed before it finished drawing the graph. It would throw an exception that is
# quite ugly to see. Let's ignore it.
return
But I end up with the same problem. I even tried not specifying the TypeError
exception and use a blanket except
, but to no avail.
Does anyone know of a way to stop Python from printing out this exception?
P.S.: I found this issue on the Python bug tracker, which seems to be related. In the attached discussion this is framed as a feature™ and not a bug, but I would still like to understand if it is possible in any way to stop this Exception from printing, especially when I am explicitly trying to catch it and ignore it.