Stream API use when there are >60s gaps between write operations [Solved]

I think I solved my own problem.

I reverted back to the stream API and used multiprocessing to run a while loop in the background. Using on_train_start(), I first open the streams (stream.open()) and then I wrote a simple hearbeater() function as follows:

training = threading.Event()
def heartbeater(training):
    while not training.isSet():
        stream.heartbeat()
        time.sleep(5)

t = threading.thread(target=heartbeater,args=(training,))
t.setDaemon(True)
t.start()

Now, the on_train_start() method will invoke the plot and spin off a separate thread to keep the connection alive. At the end of training, the on_train_end() method runs training.set(), which ends the loop.

Hope this helps someone else eventually.

[Edits: fixed a few things for as I learned more…]