示例#1
0
class SnapshotThread:

    def __init__(self, ids_queue, start_millis, end_millis, http_pool, reader_id, reader_total):
        self.__ids_queue = ids_queue
        self.__start_millis = start_millis
        self.__end_millis = end_millis
        self.__http_pool = http_pool
        self.__reader_id = reader_id
        self.__reader_total = reader_total
        self.__snapshot_reader = SnapshotReader(self.__http_pool)

    def read(self):
        global items_read
#        print self.__start_millis, self.__end_millis
        curr_millis = self.__start_millis + self.__reader_id * 1000
        while self.__end_millis == 0 or curr_millis < self.__end_millis:
            if curr_millis > int(time.time()) * 1000:
                time.sleep(self.__reader_total)
                continue

            try:
                item_ids = self.__snapshot_reader.get_snapshot(curr_millis)
                if len(item_ids) > 0:
#                    print "found", item_ids, "in", curr_millis
                    items_read += len(item_ids)

                for item_id in item_ids:
                    self.__ids_queue.put(item_id)
                curr_millis += self.__reader_total * 1000
            except HTTPError, e:
                print e
示例#2
0
 def __init__(self, ids_queue, start_millis, end_millis, http_pool, reader_id, reader_total):
     self.__ids_queue = ids_queue
     self.__start_millis = start_millis
     self.__end_millis = end_millis
     self.__http_pool = http_pool
     self.__reader_id = reader_id
     self.__reader_total = reader_total
     self.__snapshot_reader = SnapshotReader(self.__http_pool)