예제 #1
0
 def timeoutCb():
     watchdogAndDefer = self.pendingRequests.pop(tag, None)
     if watchdogAndDefer:
         (w, defer) = watchdogAndDefer
         logger.error(
             "request tag={0} is in timeout".format(tag))
         defer.callback((pbRPC_pb2.RPCBase.FAILED, None))
    def add_key(self, req_info, t):
        ''' '''
        if not self.defers:
            log.info('No defers')
            heappush(self.queue, (t, req_info))
            return

        now = time.time()
        if now >= t:
            log.info('Key %s is time execced' % req_info[0])
            defer = self.defers.popleft()
            print defer.callback
            defer.callback((req_info, t))
            if not self.defers:
                self.canceltimedcall()
            return

        if self.queue:
            nexttime = self.queue[0][0]
            if nexttime >= t:
                self.nextcall.reset(t-now)
            else:
                self.nextcall = reactor.callLater((t-now)+1.0, self.delayedcall)

        log.info('before push')
        heappush(self.queue, (t, req_info))
        log.info('after push')
예제 #3
0
 def returnSubStream(self, stream, id):
     if stream != -1:
         stream = dumps(stream)
     defer = self.dSubStream.pop(id)
     if type(defer) != list:
         defer.callback((stream, id))
     else:
         defer[0].callback(id)
 def cleanup(self):
     # cleanup defers that have timeed out for > 10 seconds
     defers = []
     for defer in self._defers:
         if (datetime.today() - defer.timestamp) > timedelta(seconds=DEFERRED_TIMEOUT):
             defer.callback(defer.request)
         else:
             defers.append(defer)
     self._defers = defers
예제 #5
0
 def returnContents(self, stream, server):
     defer = self.dContactServers.pop(server)
     if type(defer) != list:
         d = stream
         if stream != -1:
             d = [dumps(s) for s in stream]
         defer.callback((d, server))
     else:
         defer = defer[0]
         if stream != -1:
             d = [(s.id, s.title, s.author, s.description) for s in stream]
         defer.callback(d)
예제 #6
0
파일: list.py 프로젝트: gonghao/tmp_program
    def onListGot(self, result):
        data = json.loads(result['data'])
        defer = self.defers['updateList']

        if data['r'] == 0:
            songs = data['song']
            for song in songs:
                self.musics.append(Music(song))

            # callback
            defer.callback(songs)
        else:
            # errback
            defer.errback(Exception('List data got an error: %s' % data['err']))
예제 #7
0
def _try_connecting(domain, defer):
    '''
    Connects with the domain's Relay service. If it does not respond in 5 seconds
    it is assumed that the domain is not available right now 
    '''
    creator = ClientCreator(reactor,
                          TTwisted.ThriftClientProtocol,
                          RelayService.Client,
                          TBinaryProtocol.TBinaryProtocolFactory(),
                          ).connectTCP(domain, config.RELAY_PORT, timeout=10)
    creator.addCallback(lambda conn: conn.client)
    
    creator.addCallback(lambda value: defer.callback(True))
    creator.addErrback(lambda value: defer.callback(False))
예제 #8
0
파일: game.py 프로젝트: iffy/boom
 def detonateBomb(self, coord):
     """
     Detonate a bomb.
     
     @param coord: Tuple coordinate of bomb to detonate.
     """
     defer, call, size = self.bombs[coord]
     
     # Remove the bomb from the board
     del self.bombs[coord]
     
     # Let people who care know that the bomb has exploded
     defer.callback(None)
     
     # Premature explosion?
     if call.active():
         call.cancel()
     
     # Start the fires up, down, left and right
     self.startFire(coord, self.dft_burn)
     directions = [
         (0, -1),
         (0, 1),
         (-1, 0),
         (1, 0),
     ]
     for i in xrange(1, size+1):
         for d in list(directions):
             target = (coord[0]+(d[0]*i), coord[1]+(d[1]*i))
             try:
                 tile = self.fg_tiles[target]
             except KeyError:
                 continue
             if tile == HARD:
                 directions.remove(d)
                 continue
             if target in self.bombs:
                 directions.remove(d)
             if tile == SOFT:
                 directions.remove(d)
             self.startFire(target, self.dft_burn)
    def add_key(self, req_info, t):
        ''' '''
        log.info('Gotting keyword %s in add_key' % req_info[0])
        if not self.defers:
            heappush(self.queue, (t, req_info))
            return

        now = time.time()
        if now >= t:
            log.info('Key %s is time execced' % req_info[0])
            defer = self.defers.popleft()
            defer.callback((req_info, t))
            if not self.defers:
                self.canceltimedcall()
            return

        heappush(self.queue, (t, req_info))
        if self.queue:
            nexttime = self.queue[0][0]
            if nexttime >= t:
                if self.nextcall:
                    self.nextcall.reset(t-now)
            else:
                self.nextcall = reactor.callLater((t-now)+1.0, self.delayedcall)
예제 #10
0
 def returnUnregisterStream(self, id):
     defer = self.dUnregisterStream.pop(id)
     defer.callback(id)
예제 #11
0
 def returnStopProducing(self, id):
     try:
         defer = self.dStopProducing.pop(id)
     except:
         return
     defer.callback(id)
 def postAction(self, action):
     action['aid'] = len(self._actions)
     self._actions.append(action)
     for defer in self._defers:
         defer.callback(defer.request)
     del self._defers[:]