Add a signal handler to memoise.

This ensures that checkpoint files are always valid if the
user pressend CTRL+C on a running program.