示例#1
0
    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()
示例#2
0
    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()
示例#3
0
文件: script.py 项目: ess-dmsc/nicos
 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)
示例#4
0
def run_script_session(session, setup, code):
    session.handleInitialSetup(setup)
    try:
        exec(code, session.namespace)
    finally:
        session.shutdown()