mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 21:41:32 +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):
|
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,11 +68,10 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
self.monitor.pause()
|
with self.monitor.pauser:
|
||||||
try: self.filemanager.file_contents = data['content']
|
try: self.filemanager.file_contents = data['content']
|
||||||
except Exception: log.exception('Error writing file!')
|
except Exception: log.exception('Error writing file!')
|
||||||
self.restart_process()
|
self.restart_process()
|
||||||
self.monitor.resume()
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def select(self, data):
|
def select(self, data):
|
||||||
|
Loading…
Reference in New Issue
Block a user