I have a Python program which prints json objects (from intermittent messages from a game's API). When I run the program by itself, each message immediately appears in the console output.
$ python myprog.py
{"SG_MSG":{"obj_id":"SD748","aspect":"0","time":"42"}}
{"SG_MSG":{"obj_id":"SD748","aspect":"6","time":"75"}}
But when I pipe the output into jq, jq outputs nothing for ages, and sporadically spits out a bunch of messages at once:
$ python myprog.py | jq .
I've tried prepending each message with the record separator character (ascii 30) and using jq --seq .
but the result is the same.
Piping to od
shows the record separator character is appearing as the jq manual says it should:
$ python myprog.py | od -t d1
… … … 125 125 10 30 123 … …
which is }, }, LF, RS, {
And piping to od
shows the same behaviour, where no output is shown until a bunch of messages have backed up.
I'm guessing there's something elementary about bash I'm overlooking here…?