[server.py] rename initialisation steps for better clarity
initialisation occurs in this order: - object creeation (via __init__ which should consume the cfg values it knows about) - registering each object with the dispatcher - calling init_module() on each module (for connecting to other modules, checking hw, creating threads....) - calling start_module(cb) on each module. after the module finished startup it should call cb(self) once. This is the right place to do initialisation of hw which is not needed to read from the hw. (uploading curves, polling/re-setting all parameters, etc.) Change-Id: Ieaf9df5876e764634836861241f58ab986027f44 Reviewed-on: https://forge.frm2.tum.de/review/18566 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
This commit is contained in:
@ -189,21 +189,21 @@ class Module(object):
|
||||
v.unit = v.unit.replace('$', self.accessibles['value'].unit)
|
||||
|
||||
|
||||
def init(self):
|
||||
def early_init(self):
|
||||
# may be overriden in derived classes to init stuff
|
||||
self.log.debug('empty init()')
|
||||
self.log.debug('empty early_init()')
|
||||
|
||||
def postinit(self):
|
||||
self.log.debug('empty postinit()')
|
||||
def init_module(self):
|
||||
self.log.debug('empty init_module()')
|
||||
|
||||
def late_init(self, started_callback):
|
||||
'''runs after postinit of all modules
|
||||
def start_module(self, started_callback):
|
||||
'''runs after init of all modules
|
||||
|
||||
started_callback to be called when thread spawned by late_init
|
||||
or, if not implmemented, immediately
|
||||
'''
|
||||
|
||||
self.log.debug('empty late init()')
|
||||
self.log.debug('empty start_module()')
|
||||
started_callback(self)
|
||||
|
||||
|
||||
@ -238,10 +238,7 @@ class Readable(Module):
|
||||
),
|
||||
}
|
||||
|
||||
def init(self):
|
||||
Module.init(self)
|
||||
|
||||
def late_init(self, started_callback):
|
||||
def start_module(self, started_callback):
|
||||
'''start polling thread'''
|
||||
mkthread(self.__pollThread, started_callback)
|
||||
|
||||
|
@ -214,16 +214,16 @@ class Server(object):
|
||||
for devname, devobj, export in devs:
|
||||
self.log.info(u'registering module %r' % devname)
|
||||
self._dispatcher.register_module(devobj, devname, export)
|
||||
# also call init on the modules
|
||||
devobj.init()
|
||||
# call postinit on each module after registering all
|
||||
# also call early_init on the modules
|
||||
devobj.early_init()
|
||||
# call init on each module after registering all
|
||||
for _devname, devobj, _export in devs:
|
||||
devobj.postinit()
|
||||
devobj.init_module()
|
||||
starting_modules = set()
|
||||
finished_modules = Queue()
|
||||
for _devname, devobj, _export in devs:
|
||||
starting_modules.add(devobj)
|
||||
devobj.late_init(started_callback=finished_modules.put)
|
||||
devobj.start_module(started_callback=finished_modules.put)
|
||||
# remark: it is the module implementors responsibility to call started_callback
|
||||
# within reasonable time (using timeouts). If we find later, that this is not
|
||||
# enough, we might insert checking for a timeout here, and somehow set the remaining
|
||||
@ -233,6 +233,7 @@ class Server(object):
|
||||
self.log.info(u'%s has started' % finished.name)
|
||||
# use discard instead of remove here, catching the case when started_callback is called twice
|
||||
starting_modules.discard(finished)
|
||||
finished_modules.task_done()
|
||||
|
||||
def _processInterfaceOptions(self, interfaceopts):
|
||||
# eval interfaces
|
||||
|
@ -55,7 +55,7 @@ class SimBase(object):
|
||||
return newval
|
||||
setattr(self, 'write_' + k, writer)
|
||||
|
||||
def late_init(self):
|
||||
def init_module(self):
|
||||
self._sim_thread = mkthread(self._sim)
|
||||
|
||||
def _sim(self):
|
||||
|
Reference in New Issue
Block a user