Catch first keyboard interrupt

and make sure that log file gets closed and plot gets made (based on change by @saimn)