def run(cls, setup, code, mode=SLAVE, appname='script'): session.__class__ = cls try: session.__init__(appname) except Exception as err: try: session.log.exception('Fatal error while initializing') finally: print('Fatal error while initializing:', err, file=sys.stderr) return 1 # Load the initial setup and handle becoming master. session.handleInitialSetup(setup, mode) # Execute the script code and shut down. exec_(code, session.namespace) session.shutdown()
def run(cls, setup='startup', simulate=False): # Assign the correct class to the session singleton. session.__class__ = cls session.__init__('nicos') session._stoplevel = 0 session._in_sigint = False # Load the initial setup and handle becoming master. session.handleInitialSetup(setup, simulate and SIMULATION or SLAVE) # Fire up an interactive console. try: session.console() finally: # After the console is finished, cleanup. if session.mode != SIMULATION: session.log.info('shutting down...') session.shutdown()
def _setup(self): # this code is executed as the first thing when the daemon starts session.handleInitialSetup(self.setup, self.simmode) # remove this function from the user namespace after completion self.namespace.pop('NicosSetup', None)
def run_script_session(session, setup, code): session.handleInitialSetup(setup) try: exec(code, session.namespace) finally: session.shutdown()