当前位置: 首页>>代码示例>>Python>>正文


Python queue.LifoQueue类代码示例

本文整理汇总了Python中queue.LifoQueue的典型用法代码示例。如果您正苦于以下问题:Python LifoQueue类的具体用法?Python LifoQueue怎么用?Python LifoQueue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LifoQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: match_query

    def match_query(self, query):
        '''Given a search query, return a tuple containing a regex match and
        trigger object that matches the given query.  If no match can be found,
        return a tuple of (None, None).'''

        sink = LifoQueue()

        while not self.triggers.empty():
            trigger = self.triggers.get()
            match = trigger.pattern.match(query)

            if match:
                break

            else:
                sink.put(trigger)
                trigger = None

        while not sink.empty():
            self.triggers.put(sink.get())

        if trigger:
            self.triggers.put(trigger)
            return (match, trigger)

        return (None, None)
开发者ID:jreese,项目名称:congress,代码行数:26,代码来源:congress.py

示例2: AbstractMessageSender

class AbstractMessageSender(metaclass=ABCMeta):
    #delegate this to a different class
    def __init__(self):
        self.message_q = LifoQueue()
        
    def send_message(self, message, sock):
        self.add_message(message)
        sock.sendall(message.message)

    def add_message(self, message):
        self.message_q.put(message)
开发者ID:postsa,项目名称:chat_client,代码行数:11,代码来源:messagesender.py

示例3: inorder_walk

def inorder_walk(a_root_node: BSTreeNode):
    node_stack = LifoQueue()
    current_item = a_root_node
    while True:
        while current_item:
            node_stack.put(current_item)
            current_item = current_item.left_child
        if node_stack.empty():
            break
        tmp_item = node_stack.get()
        yield tmp_item

        current_item = tmp_item.right_child
开发者ID:lostinplace,项目名称:filtered-intervaltree,代码行数:13,代码来源:bs_tree_funcs.py

示例4: get_friends

def get_friends(inlist, output_path, subpath):
    ##########
    # task assignment
    ##########

    global lock
    lock = Lock()
    global q
    q = LifoQueue()  # screen_name queue
    global friend_list
    friend_list = dict()

    with open("./twitter_api_keys.pydict", "r") as f:
        keys = eval(f.read())

    # initiate task for crawler()
    for input in inlist:
        friend_list[input] = set()
        q.put({input_type: input, "count": 5000, "cursor": -1})

    for key in keys:
        t = Thread(target=uid_crawler, kwargs={"key": key, "name": keys.index(key), "rest_url": "friends/ids"})
        # t.daemon = True
        # time.sleep(2)
        t.start()

    q.join()

    # # RUN THIS AFTER FINISHED.
    try:
        mkdir("{}/{}".format(output_path, subpath))
    except OSError:
        pass

    print("writing to disk.", end=".", flush=True)
    if subpath == 0:
        for key, vals in list(friend_list.items()):
            print(".", end="", flush=True)
            with BZ2File("{}/{}/{}.bz2".format(output_path, subpath, key), "w") as f:
                f.writelines(map(lambda item: (str(item) + "\n").encode("utf-8"), vals))
    else:
        for key, vals in list(friend_list.items()):
            print(".", end="", flush=True)
            with ZipFile("{}/{}/{}.zip".format(output_path, subpath, str(key)[:3]), "a") as zf:
                zf.writestr(str(key), "\n".join([str(item) for item in vals]).encode("utf-8"), ZIP_LZMA)

    print("Done. Waiting remaining threads to quit", end=".", flush=True)
    while activeCount() > 1:
        print(activeCount(), end=".", flush=True)
        time.sleep(2)
    return friend_list
开发者ID:wliao229,项目名称:fangroup,代码行数:51,代码来源:twitter_get_egocentric.py

示例5: ThreadedNormalWorker

class ThreadedNormalWorker(object):
    def __init__(self, print_errors=False):
        self.print_errors = print_errors
        self.queue = LifoQueue()

    def get_url_bulk(self):
        normals = Normals.objects(access_success=False)
        for i in normals:
            self.queue.put(item=i)

    def grab_from_queue(self):
        while not self.queue.empty():
            url = self.queue.get()
            normals_finder = NormalsSpider(url=url.url,
                                           print_errors=self.print_errors)
            normals_finder.update_normals_data()
            print(url.url)
            self.queue.task_done()

    def start(self, n_threads):
        self.get_url_bulk()
        for i in range(n_threads):
            thread = Thread(target=self.grab_from_queue())
            thread.start()
        self.queue.join()
开发者ID:joaoTrevizoli,项目名称:climatemps-data,代码行数:25,代码来源:bots.py

示例6: __init__

    def __init__(self, size, **kwargs):
        if not isinstance(size, int):
            raise TypeError("Pool 'size' arg must be an integer")

        if not size > 0:
            raise ValueError("Pool 'size' arg must be greater than zero")

        logger.debug(
            "Initializing connection pool with %d connections", size)

        self._lock = threading.Lock()
        self._queue = LifoQueue(maxsize=size)
        self._thread_connections = threading.local()

        connection_kwargs = kwargs
        connection_kwargs['autoconnect'] = False

        for i in xrange(size):
            connection = Connection(**connection_kwargs)
            self._queue.put(connection)

        # The first connection is made immediately so that trivial
        # mistakes like unresolvable host names are raised immediately.
        # Subsequent connections are connected lazily.
        with self.connection():
            pass
开发者ID:surfacepatterns,项目名称:happybase,代码行数:26,代码来源:pool.py

示例7: __init__

 def __init__(self, name, start_url, list_of_urls, number_of_threads,
              delayed_request=False, max_allowed_error=10):
     super().__init__(name, start_url, number_of_threads,
                      delay_request=delayed_request,
                      max_err=max_allowed_error)
     self.url_list = list_of_urls
     self.task_queue = LifoQueue()
开发者ID:iiitv,项目名称:lyrics-crawler,代码行数:7,代码来源:base_crawler.py

示例8: __init__

    def __init__(self):
        QMainWindow.__init__(self)
        rec = QApplication.desktop().screenGeometry()
        self.w = rec.width()
        self.h = rec.height()
        self.kv = config.get('Settings', 'keys').split(' ')
        self.ki = 0
        self.keys = self.kv[self.ki]
        self.rect = QRectF(0, 0, self.w, self.h)
        self.shortcuts = []
        self.rects = LifoQueue()
        self.query = ''

        self.resize(self.w, self.h)
        self.setStyleSheet("background:rgba(0,0,0,%s)" % config.getfloat('Settings', 'background_opacity'))
        self.setAttribute(Qt.WA_TranslucentBackground);
        self.setWindowFlags(Qt.FramelessWindowHint);
        view = QGraphicsView(self)
        scene = QGraphicsScene()
        scene.setSceneRect(0, 0, self.w, self.h)
        view.setScene(scene)
        view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff);
        view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff);

        self.setCentralWidget(view)
        self.scene = scene
        self.drawLines()
        self.esc = QShortcut(QKeySequence('Esc'), self)
        self.esc.activated.connect(lambda: move(*config.get('Settings', 'mouse_home_coords').split(' ')))
        self.back = QShortcut(QKeySequence('Backspace'), self)
        self.back.activated.connect(self.goBack)
开发者ID:averrin,项目名称:hints,代码行数:31,代码来源:hints.py

示例9: __init__

 def __init__(self, conf, connection_class, **connection_kwargs):
     self.pid = os.getpid()
     self.conf = {"max": 0, "min": 1, "timeout": 0.1, "idle_timeout": 60, "max_lifetime": 30 * 60}
     if conf:
         self.conf.update(conf)
     self.connection_class = connection_class
     self.connection_kwargs = connection_kwargs
     self.pool = LifoQueue(self.conf["max"])
     self.diet()
开发者ID:eungju,项目名称:dongraetrader-python,代码行数:9,代码来源:connection.py

示例10: breadth_first_search

def breadth_first_search(start, goal):
    visited = [[False for x in range(500)] for y in range(500)]
    dad = [[None for x in range(500)] for y in range(500)]

    queue = Queue()
    visited[start.first()][start.second()] = True
    dad[start.first()][start.second()] = start
    current_node = start
    neighbours_ = neighbours(current_node)

    if not goal.first() - 10 <= current_node.first() <= goal.first() + 10 \
            or not \
            goal.second() - 10 <= current_node.second() <= goal.second() + 10:
        for i in range(neighbours_.__len__()):
            if visited[neighbours_[i].first()][neighbours_[i].second()] \
                    is False:
                queue.put(neighbours_[i])
                visited[neighbours_[i].first()][neighbours_[i].second()] \
                    = True
                dad[neighbours_[i].first()][neighbours_[i].second()] \
                    = current_node

    while (not goal.first() - 10 <= current_node.first() <= goal.first() + 10
            or not goal.second() - 10 <= current_node.second()
            <= goal.second() + 10) and not queue.empty():
        current_node = queue.get_nowait()
        neighbours_ = neighbours(current_node)

        for i in range(neighbours_.__len__()):
            if visited[neighbours_[i].first()][neighbours_[i].second()] \
                    is False:
                queue.put(neighbours_[i])
                visited[neighbours_[i].first()][neighbours_[i].second()] \
                    = True
                dad[neighbours_[i].first()][neighbours_[i].second()] \
                    = current_node

    path = LifoQueue()
    while not current_node.first() == start.first() \
            or not current_node.second() == start.second():
        path.put(current_node)
        current_node = dad[current_node.first()][current_node.second()]

    return path
开发者ID:VickyTerzieva,项目名称:pacman,代码行数:44,代码来源:breadth_first_search.py

示例11: __init__

class QueryQueue:
    def __init__(self):
        self.queue = LifoQueue()
        self.comm_sender = CommSender()
        th = threading.Thread(target=self.send_require)
        th.start()

    def put(self, item):
        self.queue.put(item)

    def send_require(self):
        while True:
            time.sleep(1)
            c = ConnInfo.objects.all()[0]
            q = QueryInfo.objects.all()[0]
            r = RoomInfo.objects.all()[0]
            # if is logout or unconnected, only flush queue
            if c.is_log == "False" or c.is_conn == "False":
                while not self.queue.empty():
                    self.queue.get()
                continue

            # else get last item and flush queue
            if not self.queue.empty():
                query = self.queue.get()
                while not self.queue.empty():
                    self.queue.get()
                #
                m = ModeInfo.objects.all()[0]
                s = SensorInfo.objects.all()[0]
                ss = SettingInfo.objects.all()[0]
                if m.mode == 'cold' and ss.target_temp > s.current_temp:
                    query = 'standby'
                elif m.mode == 'hot' and ss.target_temp < s.current_temp:
                    query = 'standby'
                #
                q.query_speed = query
                q.save()
                r = self.comm_sender.send_msg(data={'type': 'require', 'source': r.room_number, 'speed': query})
                # if query is standby, we should change to standby immediately
                if query == 'standby' and r.json()['ack_nak'] == 'ACK':
                    q.current_speed = 'standby'
                    q.query_speed = 'None'
                    q.save()
开发者ID:bupt1309SE,项目名称:AirSlave,代码行数:44,代码来源:speed_query.py

示例12: __init__

    def __init__(self, columns=2, rows=2, allowed_paths=[Path.up, Path.right, Path.down, Path.left], verbose=False):
        self._columns = columns
        self._rows = rows
        self._allowed_paths = allowed_paths
        self._verbose = verbose

        self._pos_x = 0
        self._pos_y = 0
        self._move_history = LifoQueue()
        self._last_move = None

        self._create_grid_matrix()
开发者ID:ChyrosNX,项目名称:NephX7,代码行数:12,代码来源:p15_lattice_paths.py

示例13: benchmark_iterator

def benchmark_iterator(components: List[str], max_builds: int) -> Iterator:
    for component, category in showfast_iterator(components=components):
        curr_metric, curr_release = None, None
        queue = LifoQueue(maxsize=max_builds)

        for benchmark in get_benchmarks(component, category):
            if not benchmark['hidden']:
                release = parse_release(benchmark['build'])

                if curr_metric != benchmark['metric']:
                    curr_metric, curr_release = benchmark['metric'], release
                    queue.queue.clear()

                if release != curr_release:
                    curr_release = release
                    queue.queue.clear()

                if queue.full():
                    yield benchmark
                else:
                    queue.put(benchmark)
开发者ID:couchbase,项目名称:perfrunner,代码行数:21,代码来源:hidefast.py

示例14: __init__

    def __init__(self):
        super().__init__()
        self._handling_lock = Lock()
        self._teardown_callback_stack = LifoQueue()  # we execute callbacks in the reverse order that they were added
        self._logger = log.get_logger(__name__)
        self._handled_exceptions = Queue()

        # Set up a handler to be called when process receives SIGTERM.
        # Note: this will raise if called on a non-main thread, but we should NOT work around that here. (That could
        # prevent the teardown handler from ever being registered!) Calling code should be organized so that this
        # singleton is only ever initialized on the main thread.
        signal.signal(signal.SIGTERM, self._application_teardown_signal_handler)
        signal.signal(signal.SIGINT, self._application_teardown_signal_handler)
开发者ID:drobertduke,项目名称:ClusterRunner,代码行数:13,代码来源:unhandled_exception_handler.py

示例15: __init__

class LifoExecutor:

    def __init__(self, executor, max_workers=None):
        self.executor = executor
        self.max_workers = max_workers or executor._max_workers
        self.queue = LifoQueue()
        self.loop = asyncio.get_event_loop()
        self.sem = asyncio.Semaphore(self.max_workers)

    def submit(self, f, *args):
        future = self.loop.create_future()
        self.queue.put((future, f, args))
        self.loop.create_task(self.run_task())
        return future

    async def run_task(self):
        await self.sem.acquire()
        future, f, args = self.queue.get()
        executor_future = self.loop.run_in_executor(self.executor, f, *args)
        executor_future.add_done_callback(lambda f, ff=future: self.done_callback(future, f))

    def done_callback(self, future, executor_future):
        self.sem.release()
        future.set_result(executor_future.result())
开发者ID:pymor,项目名称:pymor,代码行数:24,代码来源:hapod.py


注:本文中的queue.LifoQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。