FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Heartbeat v2 by Garethp · Pull Request #414 · vim-vdebug/vdebug · GitHub

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
26 changes: 26 additions & 0 deletions python3/vdebug/session.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, ui, breakpoints):
self.__ex_handler = util.ExceptionHandler(self)
self.__session = None
self.listener = None
self.__heartbeat_timer = None

def dispatch_event(self, name, *args):
event.Dispatcher(self).dispatch_event(name, *args)
Expand All @@ -41,6 +42,23 @@ def listen(self):
else:
self.start_listener()

def heartbeat(self):
if not self.is_connected():
return

try:
res = self.session().api().status()

if str(res) in ("stopping", "stopped"):
self.dispatch_event("refresh", res)
return

self.__heartbeat_timer = threading.Timer(2.0, self.heartbeat)
self.__heartbeat_timer.daemon = True
self.__heartbeat_timer.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")
Expand All @@ -65,6 +83,8 @@ def run(self):
self.listen()

def stop(self):
if self.__heartbeat_timer is not None:
self.__heartbeat_timer.cancel()
if self.is_connected():
self.__session.close_connection()
elif self.is_listening():
Expand All @@ -75,6 +95,8 @@ def stop(self):
self.__ui.say("Vdebug is not running")

def close(self):
if self.__heartbeat_timer is not None:
self.__heartbeat_timer.cancel()
self.stop_listening()
if self.is_connected():
self.__session.close_connection()
Expand Down Expand Up @@ -119,7 +141,11 @@ def __new_session(self):
log.Log("refresh event", log.Logger.DEBUG)
self.dispatch_event("refresh", status)

self.__heartbeat_timer = threading.Timer(2.0, self.heartbeat)
self.__heartbeat_timer.daemon = True
self.__heartbeat_timer.start()


class Session:

def __init__(self, ui, breakpoints, keymapper):
Expand Down

Back | FazBrowse Home | New Git URL