Catching signals, or other ways of branching within a loop?


#1

With some common UNIX utilities, it is possible to send a signal to the process that will cause it to take some instantaneous action (like print out progress):

If dd receives a SIGINFO (see the status argument for stty(1)) signal, the current input and output block counts will be written to the standard error output in the same format as the standard completion message. If dd receives a SIGINT signal, the current input and output block counts will be written to the standard error output in the same format as the standard completion message and dd will exit.

Is there a way to do something similar within Julia? I have a long-running (silent) process. I’d like to be able to press a key, or send a signal, and have the process catch the input and display its status. I don’t really want something like ProgressMeter (though it’s awesome); I’d prefer to be completely silent until some action is taken.

Any ideas?

Edit: ref https://github.com/JuliaLang/julia/issues/22883


#2

It’s a rather ugly hack, but I did accomplish something like this using threads and channels. One (or more) threads would do all the work, and periodically check on a channel to see if it had anything in it. If the channel was nonempty, the working thread would take an appropriate action. While one thread was working in the background, another was foreground waiting for me to stick something in the channel.

Not exactly what you’re asking about, I think, but hopefully gives you some ideas.