示例#1
0
    def queue(self, name, code):
        """Start a script, or queue it if the script thread is busy.

        :param name: name of the script (usually the filename) or ''
        :param code: code of the script
        :returns: ok or error
        """
        if not name:
            name = None
        try:
            reqid = self.controller.new_request(
                ScriptRequest(code, name, self.user, handler=self))
        except RequestError as err:
            self.send_error_reply(str(err))
            return
        # take control of the session
        self.controller.controlling_user = self.user
        self.send_ok_reply(reqid)
示例#2
0
    def debug(self, code):
        """Start a pdb session in the script thread context.  Experimental!

        The daemon is put into debug mode.  Replies to pdb queries can be given
        using the "debuginput" command.  Stopping the debugging (with "q" at
        the pdb prompt or finishing the script) will exit debug mode.

        :param code: code to start in debug mode
        :returns: ack or error
        """
        if self.controller.status in (STATUS_IDLE, STATUS_IDLEEXC):
            if not code:
                self.send_error_reply('no piece of code to debug given')
                return
            req = ScriptRequest(code, '', self.user, handler=self)
            self.controller.debug_start(req)
        else:
            if code:
                self.send_error_reply('code to debug given, but a '
                                      'script is already running')
                return
            self.controller.debug_running()
        self.send_ok_reply(None)
示例#3
0
 def _thread_func(self, daemon):
     user = User(name=self.name, level=USER)
     controller = daemon._controller
     error_occurred = False
     while not self._stoprequest:
         try:
             barcode = self.readLine()
             if not barcode:
                 # The Tango call will do a blocking poll with typically 2s
                 # timeout, so we don't need another sleep here.
                 continue
             script = self._convert_code(*barcode.split(',', 1))
             if not script:
                 # Let the user know that the code was not recognized.
                 self._dev.Beep(12)
                 continue
             try:
                 controller.new_request(ScriptRequest(
                     script, '<barcode request>', user))
             except RequestError:
                 self.log.warning('could not initiate request from barcode',
                                  exc=1)
                 self._dev.Beep(12)
             else:
                 # Acknowledge receipt and execution.
                 self._dev.Beep(25)
             error_occurred = False
         except Exception:
             # Happens e.g. when the Tango server is restarted during a
             # readLine call.  Log only once, to avoid continuous spamming.
             if not error_occurred:
                 self.log.warning('error waiting for barcode', exc=1)
                 error_occurred = True
             # Also leave some time inbetween attempts; if the Tango server
             # is not coming back we don't want to busy-loop.
             time.sleep(3)