I have a Julia script that runs on a remote machine. The main julia process running this script launches local julia worker processes and waits for AMQP messages that contain input data for a computation. The results of the computation are then packed into an AMQP message and returned. We’re trying to set things up so if one of the julia worker processes on the remote machine errors, we can exit gracefully and send the error and a backtrace back via AMQP. In some cases we can just wrap everything in a try/catch block, intercept exceptions that way and then send the error message to a logger that writes to an IOBuffer that we can put in an AMQP message.
However, this doesn’t always work. In particular, if one of the julia worker processes ccalls an external library and that crashes, then an error message seems to get sent to stderr but we don’t seem to be able to capture that as a log event. I’m wondering if instead, we can just redirect stderr to an IOBuffer or some julia object such that we can grab everything being sent to stderr while still inside julia and then use Julia to pack it into an AMQP message to be sent off somewhere.
I’m aware of the
redirect_stderr function but I’m having trouble using it. I don’t seem to be able to redirect to an IOBuffer(). The docs say that I can only redirect to a TTY, a pipe or a socket. I haven’t been able to find enough documentation on pipes and sockets to figure out how I can capture this output inside julia. Any suggestions on a solution or pointers on where to look for documentation would be much appreciated. I’m sorry I haven’t been able to distill this down to some sort of MWE.