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(minconn, maxconn, *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(conn, key=None, close=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(minconn, maxconn, *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(minconn, maxconn, *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(minconn, maxconn, *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.
python三种数据库连接池方式的更多相关文章
- 21Spring_JdbcTemplatem模板工具类的使用——配置文件(连接三种数据库连接池)
上一篇文章提到过DriverManagerDataSource只是Spring内置的数据库连接池,我们可选的方案还有c3p0数据库连接池以及DBCP数据库连接池. 所以这篇文章讲一下上面三种数据库连接 ...
- Spring JDBC模版以及三种数据库连接池的使用
jar包版本有点乱,直接忽略版本号,将就一下. 这里引了aop包是因为在spring3版本之后用模版对数据库库操作时会出现问题,但是不会报错,也没有提示. 所以这里直接引入,以及之后会用到的DBCP与 ...
- 三种数据库连接池的配置及使用(For JDBC)
DBCP 一.导包 Apache官网下载DBCP包,导入两个包路径如下: commons-dbcp-1.4-bin\commons-dbcp-1.4\commons-dbcp-1.4.jar:连接池的 ...
- springboot 多数据源(三种数据库连接池--JDBC,dbcp2,Druid)
本文使用的是springboot2.0(在配置数据源时和springboot1.X略有区别) 首先:springboot默认支持的连接池有dbcp,dbcp2, tomcat, hikari四种连接池 ...
- JdbcTemplae使用入门&&Spring三种连接池配置&&Spring配置文件引用外部properties文件
JdbcTemplate的使用 Spring为了各种支持的持久化技术,都提供了简单操作的模版和回调. JdbcTemplate 简化 JDBC 操作HibernateTemplate 简化 Hiber ...
- JDBC(三)数据库连接池(DBCP、C3P0)
前言 这段时间状态有一点浮躁,希望自己静下心来.还有特别多的东西还没有学懂.需要学习的东西非常的多,加油! 一.JDBC复习 Java Data Base Connectivity,java数据库连接 ...
- [转]详述DHCP服务器的三种IP分配方式
DHCP就是动态主机配置协议(Dynamic Host Configuration Protocol),它的目的就是为了减轻TCP/IP网络的规划.管理和维护的负担,解决IP地址空间缺乏问题.这种网络 ...
- Kubernetes的三种外部访问方式:NodePort、LoadBalancer和Ingress(转发)
原文 http://cloud.51cto.com/art/201804/570386.htm Kubernetes的三种外部访问方式:NodePort.LoadBalancer和Ingress 最近 ...
- LVS:三种负载均衡方式比较
[转自http://soft.chinabyte.com/25/13169025.shtml] 1.什么是LVS? 首先简单介绍一下LVS (Linux Virtual Server)到底是什么东西, ...
随机推荐
- hdu 2097
ps:WA了两次好像....Sky数是三个进制下的各位数之和相等...而不是都等于22...我傻逼了... 代码: #include "stdio.h" int inp(int a ...
- java equals 和hashcode
1 如果不知道怎么重载hashcode, eclipse自动代码生成工具会帮助你生成,大概的思路是设定一个int prim, 然后根据各个成员的值或者hashcode值进行某种运算即可,具体什么运 ...
- JS - To my gril
/* 这个程序的流程是 , 首先执行 构造函数 (), 然后 就去执行那个 render 渲染 , 在 render 哪里 的if else 转向应该执行的渲染方法 , 例如 commitsrende ...
- LeetCode Longest Increasing Subsequence (LIS O(nlogn))
题意: 给一个数组,求严格递增的最长递增子序列的长度. 思路: 开销是一个额外的O(n)的数组.lower_bound(begin,end,val)的功能是:返回第一个大于等于val的地址. clas ...
- java 的复用工具 - jar包
前言 Java提供了jar包的机制,使得已经开发好了的类能够顺利的被将来的工程所复用. 本章主要讲解如何使用这种工具. 包的作用 包能够将不同功用的类组织起来,从而确保类名的唯一性. 为了保证包名的唯 ...
- 跟开涛老师学shiro -- shiro简介
1.1 简介 Apache Shiro是Java的一个安全框架.目前,使用Apache Shiro的人越来越多,因为它相当简单,对比Spring Security,可能没有Spring Securi ...
- Java程序如何生成Jar、exe及安装文件
http://blog.csdn.net/luoweifu/article/details/7628006/ 一.用Eclipse生产Jar文件 首先,看一下我的项目的目录结构: 1,项目名字上面点右 ...
- 菜鳥日記:為 Github 添加 ssh
這只是一篇求真務實言簡意賅的菜鳥日記 記錄了碼盲在OSX 中為Github添加 ssh 的過程 要從 Github 上克隆個源碼到本地,發現無 ssh 密鈅 於是開到官網幫助照貓畫虎如下: 1.打開 ...
- tomcat实现文件打开下载功能
omcat作为http的下载服务器,网上有很多办法 但我认为最简单的是: 1.直接把文件放在 tomcat6/webapps/ROOT 目录下, 2.然后在网址中访问: http://192.168. ...
- tyvj1022 - 进制转换 ——进制为负数
题目链接:https://www.tyvj.cn/Problem_Show.aspx?id=1022 #include <cstdio> #include <cstdlib> ...