check for missing supercalls to module init methods

Change-Id: I8b7fe5cdd2883fd45532a3e8ac2d7b32945b36a3
This commit is contained in:
zolliker 2021-12-21 09:46:50 +01:00
parent 245f4f48bf
commit 8253fe471b
2 changed files with 18 additions and 4 deletions

View File

@ -257,6 +257,9 @@ class Module(HasAccessibles):
self.name = name
self.valueCallbacks = {}
self.errorCallbacks = {}
self.earlyInitDone = False
self.initModuleDone = False
self.startModuleDone = False
errors = []
# handle module properties
@ -523,11 +526,12 @@ class Module(HasAccessibles):
return False
def earlyInit(self):
# may be overriden in derived classes to init stuff
self.log.debug('empty %s.earlyInit()' % self.__class__.__name__)
"""initialise module with stuff to be done before all modules are created"""
self.earlyInitDone = True
def initModule(self):
self.log.debug('empty %s.initModule()' % self.__class__.__name__)
"""initialise module with stuff to be done after all modules are created"""
self.initModuleDone = True
def pollOneParam(self, pname):
"""poll parameter <pname> with proper error handling"""
@ -569,7 +573,11 @@ class Module(HasAccessibles):
has finished its initial work
might return a timeout value, if different from default
"""
mkthread(self.writeInitParams, started_callback)
if self.writeDict:
mkthread(self.writeInitParams, started_callback)
else:
started_callback()
self.startModuleDone = True
class Readable(Module):

View File

@ -281,6 +281,8 @@ class Server:
modobj.pollerClass.add_to_table(poll_table, modobj)
# also call earlyInit on the modules
modobj.earlyInit()
if not modobj.earlyInitDone:
modobj.log.warning('missing supercall to earlyInit')
# handle attached modules
for modname, modobj in self.modules.items():
@ -296,6 +298,8 @@ class Server:
for modname, modobj in self.modules.items():
try:
modobj.initModule()
if not modobj.initModuleDone:
modobj.log.warning('missing supercall to initModule')
except Exception as e:
if failure_traceback is None:
failure_traceback = traceback.format_exc()
@ -319,6 +323,8 @@ class Server:
event = threading.Event()
# startModule must return either a timeout value or None (default 30 sec)
timeout = modobj.startModule(started_callback=event.set) or 30
if not modobj.startModuleDone:
modobj.log.warning('missing supercall to startModule')
start_events.append((time.time() + timeout, 'module %s' % modname, event))
for poller in poll_table.values():
event = threading.Event()