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


Python queue.Queue方法代码示例

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


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

示例1: __init__

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def __init__(self, *args, **kwargs):
        """Use :class:`~gnsq.Consumer` instead.

        .. deprecated:: 1.0.0
        """
        setattr(self, 'async', kwargs.pop('async', False))

        max_concurrency = kwargs.pop('max_concurrency', 0)

        if max_concurrency < 0:
            self.max_concurrency = cpu_count()
        else:
            self.max_concurrency = max_concurrency

        if self.max_concurrency:
            self.queue = Queue()
        else:
            self.queue = None

        super(Reader, self).__init__(*args, **kwargs) 
开发者ID:wtolson,项目名称:gnsq,代码行数:22,代码来源:reader.py

示例2: __init__

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def __init__(self, app):
        self.config = app.config
        self.db = app.services.db
        assert self.db is not None
        super(ChainService, self).__init__(app)
        log.info('initializing chain')
        coinbase = app.services.accounts.coinbase
        self.chain = Chain(self.db, new_head_cb=self._on_new_head, coinbase=coinbase)
        log.info('chain at', number=self.chain.head.number)
        self.synchronizer = Synchronizer(self, force_sync=None)

        self.block_queue = Queue(maxsize=self.block_queue_size)
        self.transaction_queue = Queue(maxsize=self.transaction_queue_size)
        self.add_blocks_lock = False
        self.add_transaction_lock = gevent.lock.Semaphore()
        self.broadcast_filter = DuplicatesFilter()
        self.on_new_head_cbs = []
        self.on_new_head_candidate_cbs = [] 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:20,代码来源:eth_service.py

示例3: test_messages

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def test_messages(self, test_uuids):
        user = User("test_user")
        connection = Connection("test_user", conn_id=test_uuids[1])
        connection.queue = Queue()
        connection2 = Connection("test_user", conn_id=test_uuids[2])
        connection2.queue = Queue()
        user.add_connection(connection)
        user.add_connection(connection2)
        user.add_message(
            {
                "type": "message",
                "no_history": False,
                "pm_users": [],
                "exclude_users": [],
            }
        )
        assert len(user.connections) == 2
        assert len(user.connections[0].queue.get()) == 1
        assert len(user.connections[1].queue.get()) == 1 
开发者ID:Channelstream,项目名称:channelstream,代码行数:21,代码来源:tests_basic.py

示例4: _concurrent_execute

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def _concurrent_execute(self, context, start_req, parser, pool, pool_size):
        queue = Queue()  # 任务队列

        # 将初始化请求加入任务队列
        for r in start_req:
            queue.put_nowait(r)

        if pool is None:
            pool = GeventPool(pool_size)

        greenlets = []

        while True:
            try:
                req = self._check_req(queue.get(timeout=1))
                if req.parser is None:
                    req.parser = parser
                greenlets.append(pool.spawn(req, context, queue))
            except Empty:
                break

        return [greenlet.get() for greenlet in greenlets] 
开发者ID:chihongze,项目名称:girlfriend,代码行数:24,代码来源:crawl.py

示例5: __init__

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def __init__(self, tree_hub, from_application_name=None,
                 from_cluster_name=None, with_initial=False,
                 life_span=None, metrics_tag_from=None):
        self.hub = tree_hub

        # The optional route context
        self.from_application_name = from_application_name
        self.from_cluster_name = from_cluster_name

        self.with_initial = with_initial
        self.queue = Queue()
        self.holders = set()
        self.cluster_maps = collections.defaultdict(ClusterMap)
        self.cluster_whitelist = collections.defaultdict(set)
        self.watch_map = collections.defaultdict(set)
        self.life_span = life_span
        self._metrics_tag_from = metrics_tag_from 
开发者ID:huskar-org,项目名称:huskar,代码行数:19,代码来源:watcher.py

示例6: test_anonymous_no_concurrent_limit_because_remain_count

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def test_anonymous_no_concurrent_limit_because_remain_count(
        client, client_ip, mocker, url):
    mocker.patch.object(settings, 'CONCURRENT_LIMITER_SETTINGS', {
        '__anonymous__': {
            'ttl': 100,
            'capacity': 100,
        }
    })

    def worker(queue):
        response = client.get(url)
        if response.status_code == 429:
            queue.put(429)

    greenlets = []
    queue = Queue()
    for _ in range(3):
        greenlets.append(gevent.spawn(worker, queue))

    gevent.joinall(greenlets)
    with raises(Empty):
        queue.get_nowait() 
开发者ID:huskar-org,项目名称:huskar,代码行数:24,代码来源:test_http_concurrent_limit.py

示例7: test_logged_no_concurrent_limit_because_remain_count

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def test_logged_no_concurrent_limit_because_remain_count(
        client, client_ip, test_user, test_token, mocker):
    mocker.patch.object(settings, 'CONCURRENT_LIMITER_SETTINGS', {
        test_user.username: {
            'ttl': 100,
            'capacity': 100,
        }
    })

    def worker(queue):
        response = client.get(
            '/api/busy_with_login', headers={
                'Authorization': test_token,
            })
        if response.status_code == 429:
            queue.put(429)

    greenlets = []
    queue = Queue()
    for _ in range(3):
        greenlets.append(gevent.spawn(worker, queue))

    gevent.joinall(greenlets)
    with raises(Empty):
        queue.get_nowait() 
开发者ID:huskar-org,项目名称:huskar,代码行数:27,代码来源:test_http_concurrent_limit.py

示例8: test_anonymous_with_rate_limit

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def test_anonymous_with_rate_limit(client, client_ip, mocker, configs, url):
    cfg = deepcopy(configs[0])
    if '127.0.0.1' in cfg:
        cfg[client_ip] = cfg.pop('127.0.0.1')
    mocker.patch.object(settings, 'RATE_LIMITER_SETTINGS', cfg)

    def worker(queue):
        response = client.get(url)
        if response.status_code == 429:
            queue.put(429)

    greenlets = []
    queue = Queue()
    for _ in range(5):
        greenlets.append(gevent.spawn(worker, queue))

    gevent.joinall(greenlets)
    assert queue.get_nowait() == 429 
开发者ID:huskar-org,项目名称:huskar,代码行数:20,代码来源:test_http_rate_limit.py

示例9: test_anonymous_no_rate_limit_because_remain_count

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def test_anonymous_no_rate_limit_because_remain_count(
        client, client_ip, mocker, url):
    mocker.patch.object(settings, 'RATE_LIMITER_SETTINGS', {
        '__anonymous__': {
            'rate': 100,
            'capacity': 300,
        }
    })

    def worker(queue):
        response = client.get(url)
        if response.status_code == 429:
            queue.put(429)

    greenlets = []
    queue = Queue()
    for _ in range(3):
        greenlets.append(gevent.spawn(worker, queue))

    gevent.joinall(greenlets)
    with raises(Empty):
        queue.get_nowait() 
开发者ID:huskar-org,项目名称:huskar,代码行数:24,代码来源:test_http_rate_limit.py

示例10: test_logged_no_rate_limit_because_remain_count

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def test_logged_no_rate_limit_because_remain_count(
        client, client_ip, test_user, test_token, mocker):
    mocker.patch.object(settings, 'RATE_LIMITER_SETTINGS', {
        test_user.username: {
            'rate': 100,
            'capacity': 300,
        }
    })

    def worker(queue):
        response = client.get(
            '/api/need_login', headers={
                'Authorization': test_token,
            })
        if response.status_code == 429:
            queue.put(429)

    greenlets = []
    queue = Queue()
    for _ in range(3):
        greenlets.append(gevent.spawn(worker, queue))

    gevent.joinall(greenlets)
    with raises(Empty):
        queue.get_nowait() 
开发者ID:huskar-org,项目名称:huskar,代码行数:27,代码来源:test_http_rate_limit.py

示例11: _run_queue_item

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def _run_queue_item(self, item):
        name, args, kwargs = item
        if __debug__:
            self.logger.debug("Queue running {} with args '{}' kwargs '{}'"
                              .format(name, args, kwargs))
        try:
            func = getattr(self, name, None)
            if func is None:
                raise NotImplementedError(
                    "Item {} has been enqueued that has no valid function!"
                    .format(name))
            func(*args, **kwargs)
        except self.queue_exceptions as e:
            self.logger.error("Unable to process queue item, retrying! "
                              "{} Name: {}; Args: {}; Kwargs: {};"
                              .format(e, name, args, kwargs))
            return "retry"
        except Exception:
            # Log any unexpected problem, but don't retry because we might
            # end up endlessly retrying with same failure
            self.logger.error("Unkown error, queue data discarded!"
                              "Name: {}; Args: {}; Kwargs: {};"
                              .format(name, args, kwargs), exc_info=True) 
开发者ID:simplecrypto,项目名称:powerpool,代码行数:25,代码来源:base.py

示例12: main

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def main():
    print('请注意,代理数是固定的,原理是从66ip.cn上获取的ip,它是按时间排序的,所以建议一段时间获取一次,可以同步该网站的更新。')
    num = input('请输入你获取的代理数(建议500-2000):')
    r = requests.get(
        'http://www.66ip.cn/mo.php?sxb=&tqsl={}&port=&export=&ktip=&sxa=&submit=%CC%E1++%C8%A1&textarea=http%3A%2F%2Fwww.66ip.cn%2F%3Fsxb%3D%26tqsl%3D10%26ports%255B%255D2%3D%26ktip%3D%26sxa%3D%26radio%3Dradio%26submit%3D%25CC%25E1%2B%2B%25C8%25A1'.format(num))
    r.encoding = 'gb2312'

    result = re.findall(r'\d+[.]\d+[.]\d+[.]\d+[:]\d+', r.text)

    gevent_pool = gevent.pool.Pool(len(result))
    print(len(result))
    queue = Queue()
    for proxy in result:
        gevent_pool.apply_async(validate, (proxy, queue))
    gevent_pool.join()

    useful_proxies = []
    queue.put(StopIteration)
    with open('免费可用.txt', 'w') as f:
        for item in queue:
            useful_proxies.append(item)
            f.write(item + '\n')
    print('通过数量:', len(useful_proxies))
    print('通过率:', str(len(useful_proxies)/len(result)*100) + '%')
    return useful_proxies 
开发者ID:nikan1996,项目名称:nike_purchase_system,代码行数:27,代码来源:get_free_proxies.py

示例13: subscribe

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def subscribe():
    def gen():
        q = Queue()
        subscriptions.append(q)
        try:
            while True:
                result = q.get()
                event = ServerSentEvent(str(result))
                yield event.encode()
        except GeneratorExit:
            subscriptions.remove(q)

    return Response(gen(), mimetype="text/event-stream") 
开发者ID:jtyoui,项目名称:Jtyoui,代码行数:15,代码来源:keras_web.py

示例14: add

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def add(self, item):
        """ :type item: DataModelEvent """

        for q in self.queues.values():
            if isinstance(q, Queue):
                q.put(json.dumps(item)) 
开发者ID:mitre,项目名称:cascade-server,代码行数:8,代码来源:session.py

示例15: __init__

# 需要导入模块: from gevent import queue [as 别名]
# 或者: from gevent.queue import Queue [as 别名]
def __init__(self, nsqd_tcp_addresses=[], max_backoff_duration=128,
                 **kwargs):
        if not nsqd_tcp_addresses:
            raise ValueError('must specify at least one nsqd or lookupd')

        self.nsqd_tcp_addresses = parse_nsqds(nsqd_tcp_addresses)
        self.max_backoff_duration = max_backoff_duration
        self.conn_kwargs = kwargs
        self.logger = logging.getLogger(__name__)

        self._state = INIT
        self._connections = Queue()
        self._connection_backoffs = defaultdict(self._create_backoff)
        self._response_queues = {}
        self._workers = Group() 
开发者ID:wtolson,项目名称:gnsq,代码行数:17,代码来源:producer.py


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