I finally figured it out, after changing my code to output the lines per the number of rows of output, instead of until data[0] was blank. It turned out that data[0] was sometimes blank, and I forgot about that, and was stopping the output after I got back an empty record (or so I thought).
So, all my fault.
The syslog thing I fixed by changing log_min_duration to 0, instead of letting it default. I don't think this used to be the default (to not log any statements).