mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 07:51:55 +00:00
Merge pull request #16 from avatao-content/pmgeh_monitorpasuse_fix
Fix monitor pausing rendered useless by pmgeh, general webide optimization
This commit is contained in:
commit
a785a1a76f
@ -1,3 +1,5 @@
|
||||
from functools import wraps
|
||||
|
||||
from tfw.event_handler_base import TriggerlessEventHandler
|
||||
from tfw.components.mixins import SupervisorMixin
|
||||
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
||||
@ -16,12 +18,23 @@ class ProcessManager(SupervisorMixin):
|
||||
|
||||
|
||||
class ProcessManagingEventHandler(TriggerlessEventHandler):
|
||||
def __init__(self, key):
|
||||
def __init__(self, key, dirmonitor=None):
|
||||
super().__init__(key)
|
||||
self.key = key
|
||||
self.monitor = dirmonitor
|
||||
self.processmanager = ProcessManager()
|
||||
self.uplink = ServerUplinkConnector()
|
||||
|
||||
def _with_monitor_paused(fun):
|
||||
@wraps(fun)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
if self.monitor:
|
||||
with self.monitor.pauser:
|
||||
return fun(self, *args, **kwargs)
|
||||
return fun(self, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
@_with_monitor_paused
|
||||
def handle_event(self, key, data_json):
|
||||
data = data_json['data']
|
||||
self.processmanager(data['command'], data['process_name'])
|
||||
|
@ -53,8 +53,12 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
'select': self.select
|
||||
}
|
||||
|
||||
self.monitor = DirectoryMonitor(directory)
|
||||
self.monitor.watch() # This runs on a separate thread
|
||||
self._monitor = DirectoryMonitor(directory)
|
||||
self._monitor.watch() # This runs on a separate thread
|
||||
|
||||
@property
|
||||
def monitor(self):
|
||||
return self._monitor
|
||||
|
||||
def read(self, data):
|
||||
try: data['content'] = self.filemanager.file_contents
|
||||
@ -67,6 +71,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
with self.monitor.pauser:
|
||||
try: self.filemanager.file_contents = data['content']
|
||||
except Exception: log.exception('Error writing file!')
|
||||
del data['content']
|
||||
return data
|
||||
|
||||
def select(self, data):
|
||||
|
@ -7,9 +7,11 @@ from tfw.config import tfwenv
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
eventhandlers = {SourceCodeEventHandler('webide', tfwenv.WEBIDE_WD),
|
||||
TerminadoEventHandler('terminado', 'terminado'),
|
||||
ProcessManagingEventHandler('processmanager')}
|
||||
ide = SourceCodeEventHandler('webide', tfwenv.WEBIDE_WD)
|
||||
terminado = TerminadoEventHandler('terminado', 'terminado')
|
||||
processmanager = ProcessManagingEventHandler('processmanager', ide.monitor)
|
||||
|
||||
eventhandlers = {ide, terminado, processmanager}
|
||||
try:
|
||||
IOLoop.instance().start()
|
||||
finally:
|
||||
|
Loading…
Reference in New Issue
Block a user