PyPlot.jl
PyPlot.jl copied to clipboard
Crashing Julia on Ctrl+C
Loop termination crashes Julia process if I'm using PyPlot inside the loop. PyPlot.backend is "qt5agg" Julia 0.6.0
using PyPlot
for i=1:1000
plot(randn(32))
sleep(0)
end
Traceback (most recent call last):
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 197, in __draw_idle_agg
FigureCanvasAgg.draw(self)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\backends\backend_agg.py", line 464, in draw
self.figure.draw(self.renderer)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\figure.py", line 1144, in draw
renderer, self, dsu, self.suppressComposite)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\axes\_base.py", line 2426, in draw
mimage._draw_list_compositing_images(renderer, self, dsu)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\lines.py", line 822, in draw
drawFunc(renderer, gc, tpath, affine.frozen())
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\lines.py", line 1267, in _draw_lines
self._lineFunc(renderer, gc, path, trans)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\lines.py", line 1293, in _draw_solid
renderer.draw_path(gc, path, trans)
File "C:\Users\Yury Parfenov\.julia\v0.6\Conda\deps\usr\lib\site-packages\matplotlib\backends\backend_agg.py", line 166, in draw_path
self._renderer.draw_path(gc, path, transform, rgbFace)
KeyboardInterrupt
I also have a weird and long-standing (since at least Julia 0.4.7) issue with PyPlot and ctrl-C. This is for a Windows 10 installation. Once my code begins and PyPlot is imported, Ctrl-C no longer works in the REPL to interrupt my code. What happens instead is that the keypush of Ctrl-C is somehow 'saved', so that the next time a PyPlot function call is executed, the very old Ctrl-C keypush finally interrupts the code.
I have a similar issue: if I want to interrupt the execution of my code in the middle of a for loop containing 'plot' (useful for animations) using Ctrl+C, PyPlot
hangs and eventually Julia crashes. I'm using PyPlot and Qt5 as a backend. Any workarounds? I'm on Julia 1.0.2.
Once my code begins and PyPlot is imported, Ctrl-C no longer works in the REPL to interrupt my code.
I think what is happening is that the PyCall gui event loop, which is happening in an asynchronous task, is the one catching these ctrl-c signals instead of the main task.
I'm not sure if there is a way to disable interrupts just for the gui task?
Could you try editing PyCall (do dev PyCall
at the package prompt and then edit .julia/dev/PyCall/src/gui.jl
) to change install_doevent
to:
function install_doevent(doevent, sec::Real)
return Base.Timer(sec, interval=sec) do async
Base.sigatomic_begin() # like Base.disable_sigint, disable interrupts
doevent(async)
Base.sigatomic_end()
end
end
I've just done what you suggested @stevengj and unfortunately it doesn't fix the problem. Matplotlib still crashes if I do a Ctrl-C.
Does the traceback that you get come from Python? (i.e., the one in OP?) I'm a bit confused about why can KeyboardInterrupt
even fire here.
Maybe you can use sys.excepthook = traceback.print_exception
to workaround the problem? See: https://coldfix.eu/2016/11/08/pyqt-boilerplate/#handling-exceptions-pyqt5