Fix traceback when pipe is closed