Search code examples
linuxloggingpipe

Broken pipe while timestamping and appending to log file


I am running a python program like this

nohup python3 -u /home/myuser/foo.py | ts '[%Y-%m-%d %H:%M:%.S]' &>> /var/log/mylogs/foo.log &

The program processes input and prints output. It is multi-threaded, but most of the processing and all of the printing happens on one "primary" thread.

A few times now, I have run into a situation where the program tries to print but hits a BrokenPipeError: [Errno 32] Broken pipe. What can cause this to happen?

I found this question that makes me think I'm making an assumption about | ts ... &>>, like ts could die for some reason, but that seems weird and other programs I have set up the same way don't exhibit this behavior.


Solution

  • Try this :

    nohup bash -c "python3 -u /home/myuser/foo.py | ts '[%Y-%m-%d %H:%M:%.S]' &>> /var/log/mylogs/foo.log" &