mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 07:31:57 +00:00
Make DirectoryMonitor pausable using the with statement
This commit is contained in:
parent
0b3db0ae9e
commit
c2e161dad3
@ -42,3 +42,15 @@ class DirectoryMonitor:
|
||||
def stop(self):
|
||||
self.observer.stop()
|
||||
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,11 +68,10 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
|
||||
return data
|
||||
|
||||
def write(self, data):
|
||||
self.monitor.pause()
|
||||
try: self.filemanager.file_contents = data['content']
|
||||
except Exception: log.exception('Error writing file!')
|
||||
self.restart_process()
|
||||
self.monitor.resume()
|
||||
with self.monitor.pauser:
|
||||
try: self.filemanager.file_contents = data['content']
|
||||
except Exception: log.exception('Error writing file!')
|
||||
self.restart_process()
|
||||
return data
|
||||
|
||||
def select(self, data):
|
||||
|
Loading…
Reference in New Issue
Block a user