From 48124d9f7390ee5b07813c05b8b2c1040789c2b3 Mon Sep 17 00:00:00 2001 From: Alex Wallar Date: Wed, 16 Sep 2015 16:34:01 -0400 Subject: [PATCH] Commented up the heart class --- src/jammi/heart.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/jammi/heart.py b/src/jammi/heart.py index 21fb15b..a7dcf00 100644 --- a/src/jammi/heart.py +++ b/src/jammi/heart.py @@ -7,8 +7,27 @@ class Heart(object): + """ + A heartbeat class that can be used to send messages over UDP to a group + with a given rate + """ def __init__(self, host, port, rate): + """ + Initializes a multicast heart object + + Parameters + ---------- + host: string + The host of the multicast group + + port: integer + The port of the multicast group + + rate: integer + The rate per second that the messages would be sent over UDP + """ + self.host = host self.port = port self.rate = rate @@ -17,20 +36,47 @@ def __init__(self, host, port, rate): self.running = False def set_data(self, data): + """ + Sets the data being sent over UDP + + Parameters + ---------- + data: dict + A dictionary to update the current data with + """ + self.data = data return self def beat(self): + """ + Compresses and sends the formatted data over UDP + + Notes + ----- + This is not to be called independently but instead gets called by + the timed thread in `start` + """ json_str = json.dumps(self.data) zip_str = zlib.compress(json_str) self.sock.sendto(zip_str, (self.host, self.port)) return self def kill(self): + """ + Kills the heartbeat thread + """ self.running = False return self def start(self): + """ + Starts the hearbeat thread + + Notes + ----- + If the thread has already started, this will throw a RuntimeWarning + """ if self.running: raise RuntimeWarning("Heart already running") else: