Ctrl-C handling?


I was wondering if there is a clean solution yet for ctrl-C (i.e. SIGINT) handling? I’d like something simple that just causes all the threads to panic, dropping everything that need be dropped. Any idea how to achieve this?


You can’t. You can exit but you can’t force all threads to cleanly panic; they have to do this themselves. Alternatively, you could have your long-running threads periodically check some atomic panic flag but you’d have to do this in every thread.


You could also wire everything together using channels and send a termination message to all threads. There’s even the chan_signal crate that will let you listen (synchronously) for signals over a channel.