python dbpool

Trac back:http://jonpy.sourceforge.net/dbpool.html

dbpool module

Synopsis

The dbpool module is a wrapper for Python DB-API 2.0-compliant database modules to (a) keep a pool of physical connections available and (b) upgrade the modules to threadsafety level 2 , which means that threads can share logical database connections.

Usage

The module provides only one function not described by the DB-API 2.0 spec . The module is initialized by calling set_database with a reference to the underlying database module to be used and the number of physical database connections to keep in the pool. The dbpool module is then configured to act precisely like the underlying database module, except that physical database connections are not always closed when you have finished with them, and if you try to create more than one cursor on a single logical connection, a new physical connection is created for the new cursor.

When a logical database connection is no longer being used (i.e. you call the close function or all references to the connection are deleted), the physical connection is returned to the pool to be used the next time a connection is requested. If the pool is full (i.e. the limit set in the call to set_database is reached) then the phsyical database connection is closed.

Note that your code can either create one logical database connection, and then create many cursors from that, or create many logical database connections, and create one or more cursors from each of these. Either way the behaviour of the dbpool module will be the same - it will pool phsyical database connections, and only create one cursor per physical database connection.

Example:

import jon.dbpool as dbpool
import MySQLdb, MySQLdb.cursors
dbpool.set_database(MySQLdb, 5)
dbh = dbpool.connect(user="example", passwd="s3cr3t", db="example",
  cursorclass=MySQLdb.cursors.DictCursor)
dbc1 = dbh.cursor()
dbc2 = dbh.cursor()

Note that unfortunately, due to the way the DB-API works, once you have configured dbpool to act as a wrapper for a database module, you cannot re-configure with a different module.

Globals

Variables

apilevel

The string 2.0 , indicating the DB-API level.

threadsafety

The integer 2 , meaning that threads may shared the module, and database connections.

paramstyle

This variable is only available after set_database has been called. It will contain the value from the underlying database module.

Warning
Error
InterfaceError
DatabaseError
DataError
OperationalError
IntegrityError
InternalError
ProgrammingError
NotSupportedError

These exception classes are only available after set_database has been called. They are copied from the underlying database module.

Functions

set_database(dbmod, minconns)

dbmod : module
minconns : integer

Configures the dbpool module to act as a wrapper around the specified DB-API module. dbmod is a reference to the database module to use. minconns is an integer, which must be 1 or greater, which indicates the number of physical database connections of each 'type' to keep in the pool. Physical database connections are of the same 'type' if all the parameters to the DB-API connect function are the same (i.e. they are connecting to the same database, on the same host, with the same username, with the same options).

The database module to be used must have a threadsafety level of at least 1 , i.e. if the database cannot cope at all with multi-threading then there is nothing dbpool can do to make it work.

Note that you can only call this function once.

Example:

set_database(MySQLdb, 5)

connect(...)

Returns : database connection instance

This function may only be used after set_database has been called. The parameters are dependent on the underlying database module being used. A logical database connection from the pool corresponding to database connections with the parameters given is returned. If the pool is empty then a new physical connection is created.

Example:

dbh = dbpool.connect(user="example", passwd="s3cr3t", db="example")
dbc = dbh.cursor()

SD--根据订单创建出库单(相关的函数列表的介绍系列篇(2)) 创建订单样例代码参见:http://blog.csdn.net/CompassButton/archive/2007/05/09/1601712.aspx 可以根据一个订单或者部分订单项来创建出库单,代码如下:* Populating the item data lx_sales_item-ref_doc = l_vbeln. lx_sales_item-ref_item = c_000010 阅读详情

相关推荐

Fluent新手避坑:遇到‘Floating point exception’别慌,这7个排查步骤帮你搞定

本文为Fluent新手提供了遇到‘Floating point exception’错误时的7个详细排查步骤。从理解浮点异常的本质到边界条件检查、时间步长设置、求解器选择、网格优化、亚松弛因子调节以及高阶格式的取舍,帮助用户快速定位并解决问题,确保CFD仿真的稳定性和准确性。

weixin_30480075的博客 260

python的dbpoolpy库使用connect_db和数据库交互例子

python使用dbpoolpy可以方便的操作数据库数据,主要是用在关系型数据库,可以支持SQLite3, MySQL, PostgreSQL。

qingshuiwater的博客 510

在Unity3d使用yolov8的onnx模型

输出OUTPUTS是float32[1,35,8400],表示它会输出一个大小为[1, 35, 8400]的浮点数张量。这个输出张量的维度表示了检测到的目标的数量、每个目标的预测参数以及网格单元的数量。输出张量的第一个维度1表示检测到的目标数量。每个目标由35个值组成,表示目标的类别、置信度、边界框的坐标及10个特定点的位置。要取得8400个数据中置信度最高的数据,然后获取该数据其他channel的数据。运行结果:(蓝色是检测手的边框,红点是自定义的点),其中的四个数字分别表示不同的维度。

shenqingyu0605202324的博客 5603

python 进程池pool使用详解

和选用线程池来关系多线程类似,当程序中设置到多进程编程时,Python 提供了更好的管理多个进程的方式,就是使用进程池。 在利用 Python 进行系统管理的时候,特别是同时操作多个文件目录,或者远程控制多台主机,并行操作可以节约大量的时间。 当被操作对象数目不大时,可以直接利用 multiprocessing 中的 Process 动态生成多个进程,十几个还好,但如果是上百个,上千个目标,手动的去限制进程数量却又太过繁琐,此时可以发挥进程池的功效。 Pool可以提供指定数量的进程供用户调用,当有新的请求提

ayu6_1的博客 1万+

OpenCV透视变换实战:5分钟搞定歪斜证件照矫正(附完整代码)

本文详细介绍了如何使用OpenCV的透视变换技术快速矫正歪斜证件照,包含完整的Python代码实现。通过特征检测、坐标计算和矩阵变换三个核心步骤,5分钟内即可将手机拍摄的歪斜图像自动矫正为专业级证件照,大幅提升图像处理效率。

weixin_29094979的博客 481

【Unity实战】HybridCLR热更快速集成

本文假设你已经通过UPM导入了HybridCLR、Addressables、il2cpp支持并具有一定的C#基础和Unity编辑器操作能力。

u012587406的博客 4995

python常用库之DBUtils(连接池方式连接数据库)

Dbutils是一套工具,可为数据库提供可靠,持久和汇总的连接,该连接可在各种多线程环境中使用。

西京刀客 7824

STM32 AFIO时钟开启时机与复用功能解析

在嵌入式系统开发中,GPIO复用是微控制器外设配置的核心技术之一。通过复用功能,单个物理引脚可以动态切换不同功能模式,如USART通信或普通IO。其实现原理依赖于芯片内部的时钟树架构和寄存器配置机制。AFIO(Alternate Function I/O)模块作为STM32的特色设计,专门处理引脚重映射、外部中断配置等高级功能。正确理解复用功能与AFIO时钟的关系,能显著提升嵌入式开发效率,避免资源浪费。本文以STM32为例,结合引脚重映射和USART配置等典型场景,详解AFIO时钟的实际应用规范与优化实践

weixin_42389113的博客 579

python使用dbpoolpy快速方便的和数据库mysql交互

python使用此库可以方便的操作数据库数据,主要是用在关系型数据库,可以支持SQLite3, MySQL, PostgreSQL。

qingshuiwater的博客 383

电源防反接保护电路全攻略实战A04

本文深入剖析了硬件设计中电源保护电路的关键技术与实战经验。文章指出,保护电路虽小但至关重要,通过对比分析二极管与MOSFET防反接方案,揭示了MOSFET在效率、温控方面的优势。针对过压保护,重点讲解了TVS二极管选型要点,强调钳位电压而非击穿电压才是保护核心。文章结合工业案例(如48V通信模块烧毁、5V系统MOSFET过热等),详细阐述了PCB布局规范、热设计路径等工程细节,并提供了USB接口ESD防护的完整选型方案。最后强调硬件设计必须考虑最坏工况,在成本与性能间找到平衡点,避免因小失大。

启芯硬件的博客 777

开源模型应用落地-qwen模型小试-入门篇(二)

在windows环境下,使用transformer设置模型参数/System Prompt/历史对话

以微薄之力,予他人些许温暖. 3237

Python学习笔记之进程池pool

Pool类可以提供指定数量的进程供用户调用,当有新的请求提交到Pool中时,如果池还没有满,就会创建一个新的进程来执行请求。如果池满,请求就会告知先等待,直到池中有进程结束,才会创建新的进程来执行这些请求。

json_li的博客 5885

C++ int转四字节数组

字节转换

我不是码农的博客~~~ 973

Python爬虫之Js逆向案例(10)-数据批量写入mysql数据库

最近收到小伙伴们的私信,说如何将爬取的数据批量存到数据库中?数据入库也是童鞋们必须掌握的技能!数据回来之后,肯定需要存放,实效高、数量少的可能大多存放在cvs文件中,通常情况都是要存放到数据库的,本案例以掘金综合列表数据为例进行演示!

玛卡`三少 的博客 941

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Python下Mysql数据连接池——单例

# coding:utf-8 import threading import pymysql from DBUtils.PooledDB import PooledDB from app.common.file_config import get_config class DbPool(object): _instance_lock = threa...

weixin_30535843的博客 617

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

python数据库连接池单例_python 单例与数据库连接池 及相关选择

单例:专业用来处理连接多的问题(比如连接redis,zookeeper等),全局只有一个对象单例代码def singleton(cls):instances = {}def _singleton(*args, **kwargs):if cls not in instances:instances[cls] = cls(*args, **kwargs)return instances[cls]ret...

weixin_39552874的博客 108

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

2013.09.04更新——【Firefly API 新版文档】Package dbentrust

package dbentrust 该包下面主要是数据库的处理与memcached存储。里面封装了,从memcached数据到python对象的映射。可以以操纵python对象的方式进行memcached中存储的数据的操作,只要在不同的进程中实例化相同名称的memobject对象,就能保证对象中的数据是一致的。还包含了将这个对象中的数据同步到数据库的出来方法。这里不需去写一句sql语句。

uxqclm的专栏 1178

XHS-Downloader 3步跑通小红书作品批量下载

XHS-Downloader 是一款小红书作品批量下载工具,可提取图文与视频作品的原始文件并自动归档。适合内容创作者、研究人员和普通用户收集素材、做内容分析。它提供图形界面、命令行、API、MCP 四种启动方式,一次粘贴多个链接即可批量获取。 ## 🚀 跑起来:从克隆仓库到第一次下载 三步完成部署与首次下载,全程不需要修改源码。 ```bash git clone https://gitc

gitblog_00375的博客 77

eventlet dbpool for postgresql &mysql

eventlet dbpool for postgresql &mysql 并发编程利器EventletEventlet是由第二人生(Secondlife)开源的高度伸缩性的Python网络编程库. 根据官方介绍大致特性如下: 非阻塞I/O模型协程(...

165

编辑一个极简单的python数据库连接池

Pymssql使用记录基于Pymssql为什么要写这个怎么做难点代码 基于Pymssql 为什么要写这个 Emmm主要还是网上说的DBPool库看的我觉得复杂 其次为sqlserver2008基本上orm库都不支持所以只能用pymssql 使用pymssql过程中,如果链接超过8个小时会被sqlserver强行掐断 怎么做 将pymssql链接缓存, 并记录链接时间,超过6小时则舍弃 使用简单的列表来进行链接的管理 难点 暂时未发现 代码 数据库链接对象 ''' EML_config = { 'ho

weixin_44247218的博客 472

Python3学习笔记(5)

此篇是作者(一个萌新)在学习Python3的一点回顾和总结(适合有java或c基础的读者观看) Scrapy 概述 目录结构 [如果读者没有看懂或者觉得我写的不好可以看官方文档,在此附上链接 ](https://scrapy-chs.readthedocs.io/zh_CN/latest/index.html) ...

youhou22的博客 274

python中mysqldb模块_Python MySQLdb模块简单封装的方法源码

日常工作中可能会需要把MySQLdb封装起来,方便查询等功能使用,今天就来给大家提供一份关于Python MySQLdb模块简单封装的方法源码,供大家参考使用。MySQLdb模块简单封装方法源码如下:#-*- encoding: utf-8 -*-__author__ = "wentianle"__version__ = "$Revision: 1.0 $"__date__ = "$Date: ...

weixin_39953578的博客 281

Python—12.1、Oracle操作

Python—12.1、Oracle操作

蓝魔的博客 725

Django 3.2 + Python 3.6 旅游数据爬虫实战:Scrapy 抓取去哪儿网 1000+ 景点数据

本文详细介绍了如何使用Django 3.2和Python 3.6结合Scrapy框架构建旅游数据爬虫,实现去哪儿网1000+景点数据的自动化抓取、清洗与存储。内容涵盖环境配置、爬虫核心实现、数据存储与清洗管道、分布式扩展与性能优化等关键步骤,为开发者提供了一套完整的旅游数据分析系统解决方案。

djai0102的博客 475

python存储数据mysql_scray使用mysql存储数据

### **scrapy使用mysql**在使用python调用mysql数据库的时候,需要引入对应的数据包```import MySQLdb```如果提示找不到对应的包,说明还需要安装对应的mysql数据库客户端操作的python包。在python3环境,或者非windows下环境都很容易通过pip等工具安装上,在windows X64上比较困难,如果直接通过pip安装,往往需要VS进行编译,一...

weixin_42515014的博客 133
上一篇: python dbpool
下一篇: Howto Backup PostgreSQL Databases Server With pg_dump command
pythoner
博客等级 码龄18年 15粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值