zoukankan      html  css  js  c++  java
  • python三种数据库连接池方式

    psycopg2.pool – Connections pooling

    Creating new PostgreSQL connections can be an expensive operation. This module offers a few pure Python classes implementing simple connection pooling directly in the client application.

    class psycopg2.pool.AbstractConnectionPool(minconnmaxconn*args**kwargs)

    Base class implementing generic key-based pooling code.

    New minconn connections are created automatically. The pool will support a maximum of about maxconn connections. *args and **kwargsare passed to the connect() function.

    The following methods are expected to be implemented by subclasses:

    getconn(key=None)

    Get a free connection and assign it to key if not None.

    putconn(connkey=Noneclose=False)

    Put away a connection.

    If close is True, discard the connection from the pool.

    closeall()

    Close all the connections handled by the pool.

    Note that all the connections are closed, including ones eventually in use by the application.

    The following classes are AbstractConnectionPool subclasses ready to be used.

    class psycopg2.pool.SimpleConnectionPool(minconnmaxconn*args**kwargs)

    A connection pool that can’t be shared across different threads.

    Note

     

    This pool class is useful only for single-threaded applications.

    class psycopg2.pool.ThreadedConnectionPool(minconnmaxconn*args**kwargs)

    A connection pool that works with the threading module.

    Note

     

    This pool class can be safely used in multi-threaded applications.

    class psycopg2.pool.PersistentConnectionPool(minconnmaxconn*args**kwargs)

    A pool that assigns persistent connections to different threads.

    Note that this connection pool generates by itself the required keys using the current thread id. This means that until a thread puts away a connection it will always get the same connection object by successive getconn() calls. This also means that a thread can’t use more than one single connection from the pool.

    Note

     

    This pool class is mostly designed to interact with Zope and probably not useful in generic applications.

  • 相关阅读:
    char、varchar、nchar、nvarchar的区别
    linux和windows下分别如何查看电脑是32位的还是64位?
    HP-Unix安装Memcache问题
    安装GCC-4.6.1详细教程
    JSTL 核心标签库 使用
    JSP && EL表达式
    UNIX环境高级编程——标准IO-实现查看所有用户
    UNIX环境高级编程——环境变量表读取/添加/修改/删除
    UNIX网络编程——进程间通信概述
    UNIX网络编程——通过UNIX域套接字传递描述符和 sendmsg/recvmsg 函数
  • 原文地址:https://www.cnblogs.com/shijingjing07/p/5764665.html
Copyright © 2011-2022 走看看