KeyboardInterrupt and BrokenPipeError handling