示例#1
0
def garbageCollect(): #Run this when we have an empty server (or during a map change...)
    global THREADS
    alives = 0
    for x, i in enumerate(THREADS):
        if not i.isAlive(): del THREADS[x]
        else: alives += 1
    log.info('Garbage Collected Threads. %s still alive...' % alives)
    if alives > config_maxthreads:
        log.error('Wow... way too many threads for our thread limit! Somethings wrong...')
示例#2
0
文件: main.py 项目: tokyo-jesus/xcex
 def next(self):
     message = self._sock.recv()
     log.info("Recieved message: %s", message)
     try:
         has, wants, user, type, amount, ts = self.__match_request(message).groups()
         return Request(user, type, amount, has, wants, ts)
     except AttributeError:
         log.error("Malformed message! %s did not match: %s", self.__match_request, message)
         return None
示例#3
0
    def avantes_measure(self):
        try:
            self.send(self.message)
            # receiving timeout
            _timeout = self.receive()

            # posix timeout should be grater then 1
            if _timeout < 1:
                _timeout = 2
            else:
                _timeout *= 2
            self.receive(_timeout)
        except posix.BusyError:
            log.info('Timeout occur in measurements')
            pass
示例#4
0
    def switch_case(self, func_name):
        """
        If message should be proceed in a specified way
        the function should be defined for this.
        Otherwise:
            send -> receive
            wait for response
            receiv <- send
            return response
        """
        device = self.message['dev']
        if getattr(self, device + '_' + func_name, lambda: True)():
            if self.send(self.message):
                self.receive()

        log.info('%s', self.message)
示例#5
0
 def avantes_info(self):
     """
     Sending message to receiver
     and expecting a dict, as an answer,
     with all parameters from the device
     """
     #receiving dict with keys (maybe all keys)
     if self.send(self.message):
         log.info('Message sended')
         if self.receive():
             log.info('Message received')
             log.info('%s', self.message)
示例#6
0
        try:
            self.message['cfg'] = args.cfg
        except AttributeError:
            self.message['cfg'] = None

        try:
            self.message['mtype'] = args.store
        except AttributeError:
            self.message['mtype'] = 'black'

        try:
            self.message['amount'] = args.amount
        except AttributeError:
            pass


args = SenderParser().getArgs()
mq_sender = Sender(args)
mq_sender.setRecvQueue()
log.info('Sender openning queues')
if mq_sender.setSendQueue(args.id):
    log.info('Sender initialized receiver queue')
    mq_sender.switch_case(mq_sender.message['type'])
else:
    mq_sender.closeRecvQueue()
    log.info('Sender closed queue')
    exit(-1)

mq_sender.closeRecvQueue()
log.info('Sender closed queue')
示例#7
0
 def authenticationSucceeded(self):
     log.info('Server authentication succeeded')
     log.debug('my credentials: authentid: %s, userid: %s' % (self.authentid, self.userid))
示例#8
0
    def buildReply(self, message):
        reply = {'reply':str(message)}
        return reply

    @_if_debug(log)
    def readQueue(self):
        while True:
            if self.receive(timeout=None):
                if 'type' in self.message.keys():
                    switch = self.switch_case(self.message['type'])
                    if switch == False:
                        if __debug__:
                            log.warning('Exiting')
                        break

        # release communication with the device
        if __debug__:
            log.warning('Removing the device')
        self.closeRecvQueue()
        self.device.release()

args = ReceiverParser().getArgs()
mq_receiver = Receiver(args)
if mq_receiver.setRecvQueue(args.id):
    log.info('New queue created %s', args.id)
    mq_receiver.readQueue()
else:
    log.warning('Using old queue %s', args.id)
    mq_receiver.readQueue()
示例#9
0
 def channelClosedError(self, channelnum, code, desc):
     """ What to do if a channel close fails
     """
     log.info("close of channel %d failed: %s: %s" % (channelnum, code, desc))
     pass
示例#10
0
        self.ID = sessId

    def validateFrame(self, theframe):
        if self.channels.has_key(theframe.channelnum):
            try:
                # import nice
                # logging.debug('Received frame: \n' + nice.hex_dump(str(theframe), 24, '    '))
                self.channels[theframe.channelnum].validateFrame(theframe)

            except TerminateException, e:
                self.close()

            except Exception, e:
                raise
        else:
            log.info("Attempt to send to non-existant channel: %d" % theframe.channelnum)
            raise SessionException("Invalid Channel Number")

    def processFrame(self, theframe):
        """
        Allocate a given frame to the channel it belongs to
        and call the channel's processing method.

        @param theframe: the frame to process
        @type theframe: a DataFrame object
        """
        #        log.debug('processing frame: %s' % theframe)

        if self.channels.has_key(theframe.channelnum):
            try:
                # import nice