zoukankan      html  css  js  c++  java
  • kombu中 acquire函数中block参数的解释

    一直都想知道acquire中block参数的含义,今天查阅相关文档,如下别有一番洞天

    Connection and Producer Pools

    Default Pools

    Kombu ships with two global pools: one connection pool, and one producer pool.

    These are convenient and the fact that they are global may not be an issue as connections should often be limited at the process level, rather than per thread/application and so on, but if you need custom pools per thread see Custom Pool Groups.

    The connection pool group

    The connection pools are available as kombu.pools.connections. This is a pool group, which means you give it a connection instance, and you get a pool instance back. We have one pool per connection instance to support multiple connections in the same app. All connection instances with the same connection parameters will get the same pool:

    >>> from kombu import Connection
    >>> from kombu.pools import connections
    
    >>> connections[Connection('redis://localhost:6379')]
    <kombu.connection.ConnectionPool object at 0x101805650>
    >>> connections[Connection('redis://localhost:6379')]
    <kombu.connection.ConnectionPool object at 0x101805650>
    

    Let’s acquire and release a connection:

    from kombu import Connection
    from kombu.pools import connections
    
    connection = Connection('redis://localhost:6379')
    
    with connections[connection].acquire(block=True) as conn:
        print('Got connection: {0!r}'.format(connection.as_uri()))
    

    Note

    The block=True here means that the acquire call will block until a connection is available in the pool. Note that this will block forever in case there is a deadlock in your code where a connection is not released. There is a timeout argument you can use to safeguard against this (see kombu.connection.Resource.acquire()).

    If blocking is disabled and there aren’t any connections left in the pool an kombu.exceptions.ConnectionLimitExceeded exception will be raised.

  • 相关阅读:
    linux环境变量
    oracle 11g RAC日志分布
    解决Centos下载文件出现”wget: unabl(www.111cn.net)e to resolve host address”
    转载:root用户无法删除文件 rm: cannot remove Readonly file system
    占用端口
    数学小记
    很多问题的解决都是从简单的方式入手不断优化的
    机器学习之算法学习
    机器学习之二分类
    机器学习之模型评估(损失函数的选择)
  • 原文地址:https://www.cnblogs.com/L-O-N/p/13596959.html
Copyright © 2011-2022 走看看