Use IO.pipe to move the signal handling outside the trap context