diff --git a/plotly/plotly/plotly.py b/plotly/plotly/plotly.py index d956f8a4af9..33c58a7a72b 100644 --- a/plotly/plotly/plotly.py +++ b/plotly/plotly/plotly.py @@ -416,6 +416,21 @@ def __init__(self, stream_id): self.stream_id = stream_id self.connected = False + def heartbeat(self, reconnect_on=(200, '', 408)): + """Keep stream alive. Streams will close after ~1 min of inactivity. + + If the interval between stream writes is > 30 seconds, you should + consider adding a heartbeat between your stream.write() calls like so: + >>> stream.heartbeat() + + """ + try: + self._stream.write('\n', reconnect_on=reconnect_on) + except AttributeError: + raise exceptions.PlotlyError("Stream has not been opened yet, " + "cannot write to a closed connection. " + "Call `open()` on the stream to open the stream.") + def open(self): """Open streaming connection to plotly.