Coverage for ion/core/bootstrap : 61.54%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#!/usr/bin/env python
@file ion/core/bootstrap.py @author Michael Meisinger @brief Main module for bootstrapping the system and support functions. Functions in here are called from ioncore application module and from test cases. """
""" @brief Initializes local container and starts services and messaging from given setup args. @param messaging dict of messaging name configuration dicts (obsolete) @param services list of services (as svc description dict) to start up @retval Deferred -> supervisor Process instance """ log.info("Init container, configuring messaging and starting services...") yield init_ioncore() sup = None if messaging: raise NotImplementedError("bootstrap: messaging configuration not supported") #assert type(messaging) is dict #yield declare_messaging(messaging) if services: assert type(services) is list sup = yield spawn_processes(services)
defer.returnValue(sup)
""" Performs global initializations on the local container on startup. @retval Deferred """ # Extract command line args and set with Container instance
# Collect all service declarations in local code modules #ModuleLoader().load_modules()
# @todo Service registry call for local service/version registration #yield bs_register_services()
try: # Evaluate args and expect they are dict as str evargs = eval(contargs) if type(evargs) is dict: ioninit.cont_args.update(evargs) except Exception, e: log.error('Invalid argument format: ', e) # Key=value arguments separated by comma else: ioninit.cont_args['args'] = contargs Container.id = ioninit.cont_args['contid'] else:
''' This method is out of date with the service registry @defer.inlineCallbacks def bs_register_services(): """ Register all the declared processes. """ src = service_registry.ServiceRegistryClient() for proc in process.processes.values(): sd = service_registry.ServiceDesc() sd.name = proc['name'] res = yield src.register_service(sd) ''' """ Resets the container for warm restart. Simple implementation currently. Used for testing only. """ # The following is extremely hacky. Reset static module and classvariables # to their defaults. Even further, reset imported names in other modules # to the new objects.
# reset things set by _set_container_args #ioninit.cont_args.pop('contid', None)
# Use SIGALARM to detect busy loops, where the reactor is not getting to process events. # Monkey-patch the reactor to count iterations, to show it's not blocked. Int overflow shouldn't break it. # This needs to only be done once per reactor, and not once per container, so it's package-level code.
reactorStepCount = 0 _doIteration = getattr(reactor, 'doIteration') def doIterationWithCount(*args, **kwargs): global reactorStepCount reactorStepCount += 1 _doIteration(*args, **kwargs) setattr(reactor, 'doIteration', doIterationWithCount)
lastReactorStepCount = 0 def alarm_handler(signum, frame): global lastReactorStepCount signal.alarm(1)
if reactor.running and reactorStepCount == lastReactorStepCount: log.critical('Busy loop detected! The reactor has not run for >= 1 sec. ' +\ 'Currently at %s():%d of file %s.' % ( frame.f_code.co_name, frame.f_lineno, frame.f_code.co_filename))
### uncomment to print traceback... #import traceback; traceback.print_stack(frame)
lastReactorStepCount = reactorStepCount
signal.signal(signal.SIGALRM, alarm_handler) signal.alarm(1) |