Exemplo n.º 1
0
 def MainLoop(self):
     """This is the main loop. It does not have a subclass-overridable companion,
     however it has a number of main_ methods which are intended to be overridden.
     
     It runs until self.done is true.
     """
     self.main_doPrompt()
     while not self.done:
         visitstate = simV2.VisItDetectInputWithTimeout(
             self.truth_to_0_1(self.runMode == simV2.VISIT_SIMMODE_STOPPED),
             self.console_timeout, sys.stdin.fileno())
         if visitstate == 0:
             self.cmd_step(None, None, None, None)
         elif visitstate == 1:
             if simV2.VisItAttemptToCompleteConnection(
             ) == simV2.VISIT_OKAY:
                 self.runMode = simV2.VISIT_SIMMODE_STOPPED
                 self.main_doVisItConnect()
         elif visitstate == 2:
             if simV2.VisItProcessEngineCommand() != simV2.VISIT_OKAY:
                 simV2.VisItDisconnect()
                 self.runMode = simV2.VISIT_SIMMODE_RUNNING
         elif visitstate == 3:
             cmd = simV2.VisItReadConsole()
             self.main_doConsoleCommand(cmd)
             self.main_doPrompt()
         else:
             self.main_visitstateError(visitstate)
     return
Exemplo n.º 2
0
 def Disconnect(self):
     """
     Handle VisIt disconnect
     """
     if self._Connected:
         self.DisconnectLibsim()
         simV2.VisItDisconnect()
         self._Connected = False
     return
Exemplo n.º 3
0
    def EventLoop(self):
        """
        Run the VisIt controlled event loop. Return False on error
        """
        doError = lambda e: e < 0
        doUpdate = lambda e: e == 0
        doConnect = lambda e: e == 1
        doInternal = lambda e: e == 2
        masterRank = lambda r: r == 0
        onErrorContinue = lambda: self._Behavior == 'Monitor'

        if __debug__: pDebug('WarpVisItEngine::EventLoop')

        while 1:
            # test or wait for incomming communication.
            if masterRank(self._CommRank):
                event = simV2.VisItDetectInput(self._VisItBlockingComm, -1)
                parallel.broadcast(event)
            else:
                event = parallel.broadcast(0)

            # process incomming communication
            if __debug__: pDebug('event=%d' % (event))

            # internal comm error
            if doError(event):
                # the VisIt viewer disconnected.
                pError('An communication error was detected')
                self._Behavior.Initialize()
                if onErrorContinue():
                    continue
                else:
                    return False

            # simulate
            elif doUpdate(event):
                # this is where we can safely do things.
                # it occurs only when VisIt is not in the
                # middle of processing its own commands.
                if __debug__: pDebug('update')
                self._Behavior.Update()
                # TODO -- is it useful to force gc??
                #gc.collect()

            # internal connection
            elif doConnect(event):
                if simV2.VisItAttemptToCompleteConnection() == 1:
                    pStatus('WarpVisItEngine connected')
                    self.ConnectLibsim()
                    self._Behavior.Connect()
                    self._Behavior.Update()
                else:
                    pError('Connection failed')
                    self._Behavior.Initialize()
                    if onErrorContinue():
                        continue
                    else:
                        return False

            # internal comm
            elif doInternal(event):
                if __debug__: pDebug('internal')
                if not self.CommunicateLibsim():
                    pError('Error while processing internal commands')
                    self._Behavior.Initialize()
                    if onErrorContinue():
                        continue
                    else:
                        return False

            # bad value
            else:
                pError('unknown command %d' % (event))

            # check for asynchronous shutdown request
            if self._ShutdownRequested:
                pStatus('WarpVisItEngine exiting the event loop')
                simV2.VisItDisconnect()
                self._Connected = False
                return True

            continue

        return False