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

Skip to content

Add a heartbeat method to the py.Stream class (more below) #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down