Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cad4279

Browse files
committed
Merge pull request plotly#137 from plotly/streaming-heartbeat
Add a heartbeat method to the py.Stream class (more below)
2 parents f1bcf0d + 923f4e2 commit cad4279

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

plotly/plotly/plotly.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,21 @@ def __init__(self, stream_id):
424424
self.stream_id = stream_id
425425
self.connected = False
426426

427+
def heartbeat(self, reconnect_on=(200, '', 408)):
428+
"""Keep stream alive. Streams will close after ~1 min of inactivity.
429+
430+
If the interval between stream writes is > 30 seconds, you should
431+
consider adding a heartbeat between your stream.write() calls like so:
432+
>>> stream.heartbeat()
433+
434+
"""
435+
try:
436+
self._stream.write('\n', reconnect_on=reconnect_on)
437+
except AttributeError:
438+
raise exceptions.PlotlyError("Stream has not been opened yet, "
439+
"cannot write to a closed connection. "
440+
"Call `open()` on the stream to open the stream.")
441+
427442
def open(self):
428443
"""Open streaming connection to plotly.
429444

0 commit comments

Comments
 (0)