Phil Rosenberg - 2017-10-01

This is not trivial to deal with. The way I can see to deal with it is by using signal from signal.h to catch the ctrl-C and do cleanup. E.g. as described at https://stackoverflow.com/questions/4217037/catch-ctrl-c-in-c. However, because PLplot is a library, not a program I don't think we should do this. It should be up to the calling program to catch ctrl-C and sensibly call plend to free resources. In particular the calling program may be catching ctrl-C for other reasons and we might end up overriding the calling program's catch.

However, if the calling program caught the interrupt then plend() shouldn't be immediately called because PLplot cannot cope with rentrant/multithreaded behaviour so may segfault.

Instead the user should do as https://stackoverflow.com/a/4217052/1051805 and set a volatile flag, then when PLplot returns from its current operation plend() should be called.

But then the reason the user hit ctrl-C in the first place may well be the PLplot is running an incredibly long operation, like plotting a contour plot with a very large number 2D data set. In this case we really want ctrl-C to permit aborting.

So the answer - I think what is needed is an API function to set a progress callback which has a return value that allows us to halt all plotting. For example this callback could be called every 1000 fills or line segments and if it returns false, then a flag is set in PLStream and every render operation or contour calculation becomes a no-op. This would acheive two things. A program that captured a ctrl-C signal could force relatively rapid exit of PLplot and call plend(). The other thing - that I have thought important for some time is that this would allow progress reporting and render cancelling by interactive drivers. I think this is quite important. Currently interactive drivers may appear to hang while performing long plotting operations.