diff options
author | Ike Devolder <ike.devolder@gmail.com> | 2019-07-04 23:33:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-04 23:33:09 +0200 |
commit | 1006a5ae7bfb2adc36c5085c0af625e0cc6deff3 (patch) | |
tree | 233ea75aa2cb43ce7d293598c5f9b9c685ead157 /python3 | |
parent | f16351a94bc784a7c5e20e4b1a08f2f4de34f2be (diff) | |
parent | 8736ee2cabf41a972eb80e81c1a3190884432104 (diff) | |
download | vdebug-1006a5ae7bfb2adc36c5085c0af625e0cc6deff3.zip |
Merge pull request #406 from Garethp/heartbeat
Adding a heartbeat
Diffstat (limited to 'python3')
-rw-r--r-- | python3/vdebug/session.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/python3/vdebug/session.py b/python3/vdebug/session.py index 2e0f5d0..c12188d 100644 --- a/python3/vdebug/session.py +++ b/python3/vdebug/session.py @@ -1,4 +1,5 @@ import socket +import threading import vim @@ -41,6 +42,18 @@ class SessionHandler: else: self.start_listener() + def heartbeat(self): + try: + res = self.session().api().status() + + if str(res) in ("stopping", "stopped"): + self.dispatch_event("refresh", res) + return + + threading.Timer(2.0, self.heartbeat).start() + except: + self.dispatch_event("refresh", "stopped") + def start_listener(self): self.listener = listener.Listener.create() print("Vdebug will wait for a connection in the background") @@ -118,6 +131,7 @@ class SessionHandler: status = self.__session.start(self.listener.create_connection()) log.Log("refresh event", log.Logger.DEBUG) self.dispatch_event("refresh", status) + threading.Timer(2.0, self.heartbeat).start() class Session: |