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


Python pool.ThreadedConnectionPool方法代码示例

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


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

示例1: allocate_db_connection_pool

# 需要导入模块: from psycopg2 import pool [as 别名]
# 或者: from psycopg2.pool import ThreadedConnectionPool [as 别名]
def allocate_db_connection_pool(
        connection_config: DatabaseConnectionConfig,
        max_connections: int = 20
) -> ThreadedConnectionPool:
    """
    Allocate a pool of database connections for an application

    Connecting to a database can be a costly operation for stateless
    applications that jump in and out of a database frequently,
    like a REST APIs. To combat this, a connection pool provides a set of
    persistent connections that preclude these applications from constantly
    connecting and disconnecting from the database.

    :param connection_config: data needed to establish a connection
    :param max_connections: maximum connections allocated to the application
    :return: a pool of database connections to be used by the application
    """
    log_msg = (
        'Allocating a pool of connections to the {db_name} database with '
        'a maximum of {max_connections} connections.'
    )
    _log.info(log_msg.format(
        db_name=connection_config.db_name,
        max_connections=max_connections)
    )
    return ThreadedConnectionPool(
        minconn=1,
        maxconn=max_connections,
        database=connection_config.db_name,
        user=connection_config.user,
        password=connection_config.password,
        host=connection_config.host,
        port=connection_config.port,
        cursor_factory=RealDictCursor
    ) 
开发者ID:MycroftAI,项目名称:selene-backend,代码行数:37,代码来源:connection_pool.py

示例2: _setup_db_pool

# 需要导入模块: from psycopg2 import pool [as 别名]
# 或者: from psycopg2.pool import ThreadedConnectionPool [as 别名]
def _setup_db_pool():
    from psycopg2.pool import ThreadedConnectionPool
    return ThreadedConnectionPool(1, 3, database='chen', user='chen') 
开发者ID:chenwuperth,项目名称:rgz_rcnn,代码行数:5,代码来源:parse_output.py

示例3: init_app

# 需要导入模块: from psycopg2 import pool [as 别名]
# 或者: from psycopg2.pool import ThreadedConnectionPool [as 别名]
def init_app(cls, app):
        """
        Initialize db session lazily
        """
        query_con = ("postgresql://{PG_USER}:{PG_PASSWORD}@{PG_HOST}:"
                     "{PG_PORT}/{PG_NAME}"
                     .format(**app.config))
        cls.pool = ThreadedConnectionPool(1, cpu_count(), query_con)
        # keep some configuration element
        cls.dbname = app.config["PG_NAME"] 
开发者ID:Oslandia,项目名称:lopocs,代码行数:12,代码来源:database.py

示例4: __init__

# 需要导入模块: from psycopg2 import pool [as 别名]
# 或者: from psycopg2.pool import ThreadedConnectionPool [as 别名]
def __init__(self, size, dsn=None):
        if dsn:
            self.db_pool = pool.ThreadedConnectionPool(1, size,
                                                       dbname=dsn["database"], user=dsn["user"],
                                                       host=dsn["host"], port=dsn["port"])
        else:
            self.db_pool = pool.ThreadedConnectionPool(1, size,
                                                       dbname=VMAAS_DB_NAME, user=VMAAS_DB_LOGIN,
                                                       password=VMAAS_DB_PASSWD,
                                                       host=VMAAS_DB_HOST, port=VMAAS_DB_PORT) 
开发者ID:RedHatInsights,项目名称:vmaas,代码行数:12,代码来源:db_handler.py

示例5: _createConnectionPool

# 需要导入模块: from psycopg2 import pool [as 别名]
# 或者: from psycopg2.pool import ThreadedConnectionPool [as 别名]
def _createConnectionPool(self):
        self.connectionPool = ThreadedConnectionPool(
            1,
            self.config.getProperty('Database', 'max_num_connections', type=int, fallback=20),
            host=self.host,
            database=self.database,
            port=self.port,
            user=self.user,
            password=self.password,
            connect_timeout=2
        ) 
开发者ID:microsoft,项目名称:aerial_wildlife_detection,代码行数:13,代码来源:app.py

示例6: setup_pool

# 需要导入模块: from psycopg2 import pool [as 别名]
# 或者: from psycopg2.pool import ThreadedConnectionPool [as 别名]
def setup_pool():
    global pool
    with open('htc_login.txt') as f:
      #each of these is expected to appear on  a separate line
      host = f.readline().rstrip()
      port = f.readline().rstrip()
      db   = f.readline().rstrip()
      user = f.readline().rstrip()
      pw   = f.readline().rstrip()
      pool = pgp.ThreadedConnectionPool(20, 100, host=host, port=port, database=db, user=user, password=pw)


#get current db connection if holding one, otherwise get a new one from the pool 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:15,代码来源:htc_api.py


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