mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 22:01:31 +00:00
Merge pull request #11 from avatao-content/watchdog_hotfix
Watchdog hotfix
This commit is contained in:
commit
a7e2a08166
@ -12,9 +12,17 @@ class WebideReloadEventHandler(FileSystemEventHandler):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.uplink = ServerUplinkConnector()
|
self.uplink = ServerUplinkConnector()
|
||||||
|
self._paused = False
|
||||||
|
|
||||||
|
def pause(self):
|
||||||
|
self._paused = True
|
||||||
|
|
||||||
|
def resume(self):
|
||||||
|
self._paused = False
|
||||||
|
|
||||||
@RateLimiter(rate_per_second=5)
|
@RateLimiter(rate_per_second=5)
|
||||||
def on_modified(self, event):
|
def on_modified(self, event):
|
||||||
|
if self._paused: return
|
||||||
log.debug(event)
|
log.debug(event)
|
||||||
anchor = 'anchor_webide'
|
anchor = 'anchor_webide'
|
||||||
self.uplink.send(anchor, {'anchor': anchor,
|
self.uplink.send(anchor, {'anchor': anchor,
|
||||||
@ -24,7 +32,9 @@ class WebideReloadEventHandler(FileSystemEventHandler):
|
|||||||
class DirectoryMonitor:
|
class DirectoryMonitor:
|
||||||
def __init__(self, directory):
|
def __init__(self, directory):
|
||||||
self.observer = Observer()
|
self.observer = Observer()
|
||||||
self.observer.schedule(WebideReloadEventHandler(), directory, recursive=True)
|
self.eventhandler = WebideReloadEventHandler()
|
||||||
|
self.observer.schedule(self.eventhandler, directory, recursive=True)
|
||||||
|
self.pause, self.resume = self.eventhandler.pause, self.eventhandler.resume
|
||||||
|
|
||||||
def watch(self):
|
def watch(self):
|
||||||
self.observer.start()
|
self.observer.start()
|
||||||
@ -32,3 +42,15 @@ class DirectoryMonitor:
|
|||||||
def stop(self):
|
def stop(self):
|
||||||
self.observer.stop()
|
self.observer.stop()
|
||||||
self.observer.join()
|
self.observer.join()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pauser(self):
|
||||||
|
return DirectoryMonitor.Pauser(self)
|
||||||
|
|
||||||
|
class Pauser:
|
||||||
|
def __init__(self, directory_monitor):
|
||||||
|
self.directorymonitor = directory_monitor
|
||||||
|
def __enter__(self):
|
||||||
|
self.directorymonitor.pause()
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
self.directorymonitor.resume()
|
||||||
|
@ -68,9 +68,10 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
try: self.filemanager.file_contents = data['content']
|
with self.monitor.pauser:
|
||||||
except Exception: log.exception('Error writing file!')
|
try: self.filemanager.file_contents = data['content']
|
||||||
self.restart_process()
|
except Exception: log.exception('Error writing file!')
|
||||||
|
self.restart_process()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def select(self, data):
|
def select(self, data):
|
||||||
|
Loading…
Reference in New Issue
Block a user