Example #1
0
    def timerEvent(self, event):
        """
        Periodically call updateGL to process mouse/keyboard events and
        update the scene.
        """
        etime = time.time() - self.lastFrameTime
        if etime > 1:
            numFrames = self.frameCnt - self.lastFrameCnt
            util.logMetricQty('#FPS', int(numFrames / etime))
            self.lastFrameCnt = self.frameCnt
            self.lastFrameTime = time.time()

        self.killTimer(event.timerId())
        self.drawTimer = self.startTimer(20)
        self.updateGL()
Example #2
0
    def sendToClerk(self, cmd: str, data: dict):
        """
        Send data to Clerk and return the response.

        This method blocks until a response arrives. Upon a reply it inspects
        the response to determine whether the request succeeded or not. This is
        returned as the first argument in the 'ok' flag.

        .. note::
           JSON must be able to serialise the content of ``data``.

        :param str cmd: command word
        :param dict data: payload (must be JSON encodeable)
        :return: Payload data in whatever form it arrives.
        :rtype: any
        """
        with util.Timeit('client.sendToClerk:{}:1'.format(cmd)):
            try:
                payload = json.dumps({'cmd': cmd, 'data': data})
            except (ValueError, TypeError):
                msg = 'JSON encoding error for Client command <{}>'.format(cmd)
                self.logit.warning(msg)
                return RetVal(False, msg, None)

        # Send data and wait for response.
        with util.Timeit('client.sendToClerk:{}:2'.format(cmd)):
            self.send(payload)
            payload = self.recv()

        util.logMetricQty('client.recv:{}'.format(cmd), len(payload))

        # Decode the response and wrap it into a RetVal tuple.
        with util.Timeit('client.sendToClerk:{}:3'.format(cmd)):
            try:
                ret = json.loads(payload)
                ret = RetVal(**ret)
            except (ValueError, TypeError):
                return RetVal(False, 'JSON decoding error in Client', None)

        return ret