pooling
pooling anything.
Install
pip install pooling
Usage Example 1
import MySQLdb
from MySQLdb.cursors import DictCursor
from pooling import PoolBase
class MysqlConnectionPool(PoolBase):
def do_session_create(self, *create_args, **create_kwargs):
create_kwargs.setdefault("cursorclass", DictCursor)
create_kwargs.setdefault("autocommit", True)
create_kwargs.setdefault("charset", "utf8mb4")
return MySQLdb.connect(*create_args, **create_kwargs)
def do_session_destory(self, real_session):
real_session.close()
if __name__ == "__main__":
conn_info = {
"host": "127.0.0.1",
"port": 3306,
"user": "test",
"password": "test",
"db": "test",
}
pool = MysqlConnectionPool(pool_size=10, kwargs=conn_info)
connection = pool.get_session()
cursor = connection.cursor()
count = cursor.execute("show databases")
data = cursor.fetchall()
print("rows count=", count)
print("data=", data)
assert count == len(data)
Usage Example 2
import MySQLdb
from MySQLdb.cursors import DictCursor
from pooling import Pool
def mysql_conn_create():
conn_info = {
"host": "127.0.0.1",
"port": 3306,
"user": "test",
"password": "test",
"db": "test",
}
conn = MySQLdb.connect(cursorclass=DictCursor, autocommit=True, **conn_info)
return conn
def mysql_conn_close(session):
session.close()
if __name__ == "__main__":
pool = Pool(pool_size=10, create_factory=mysql_conn_create, destory_factory=mysql_conn_close)
connection = pool.get_session()
cursor = connection.cursor()
count = cursor.execute("show databases")
data = cursor.fetchall()
print("rows count=", count)
print("data=", data)
assert count == len(data)
Usage Example 3
conn_info = {
"host": "127.0.0.1",
"port": 3306,
"user": "test",
"password": "test",
"db": "test",
}
from pooling.mysql import MysqlConnectionPool
pool = MysqlConnectionPool(10, kwargs=conn_info)
connection = pool.get_session()
cursor = connection.cursor()
count = cursor.execute("show databases")
data = cursor.fetchall()
print("rows count=", count)
print("data=", data)
assert count == len(data)
Usage Example 4
conn_info = {
"host": "127.0.0.1",
"port": 3306,
"user": "test",
"password": "test",
"db": "test",
}
from pooling.mysql import MysqlConnectionPool
pool = MysqlConnectionPool(10, kwargs=conn_info)
data = pool.query("select * from table1")
for row in data:
print(row)
Note
- Call pool.get_session() returns a proxied connection instance.
- The returned proxied connection instance is a proxy instance of the real connection.
- When the returned proxied connection is being deleted, the real connection will be returned to the pool so that the real connection can be used again.
- A simple mysql connection pool can be imported by doing
from pooling.mysql import MysqlConnectionPool. Compare with theMysqlConnectionPoolimplemented inUsage Example 1, it add ping() test and errors handler in get_session() method. - The
pooling.mysqlmodule depends onmysqlclient, butpoolingis NOT, so thatmysqlclientis not auto installed afterpoolinginstalled. You should dopip install mysqlclientby yourself if you want to useMysqlConnectionPool. - If you want to use
MysqlConnectorPool, you need to install packagemysql-connector-pythonby yourself. - If you want to use
PyMySQLConnectionPool, you need to install packagePyMySQLby yourself.
Releases
v0.1.0
- First release.
v0.1.1
MysqlConnectionPool.get_session()doconnection.ping()to make sure the connection is avaiable.Pool.counterandPool.versionuse thread safe counter.
v0.1.2
- Fix problem in using
get_sessionwithwithstatement.with pool.get_session() as session: passgot the real session instread of our wrapped Session.
v0.1.5
- Fix problem in handling a proxied real-session instance.
- Fix un-sleep-problem while connecting to mysql server failed.
- Add python2.7 support.
v0.1.6
- Use zenutils.importutils.
- Fix get_session timeout calc problem.
v0.1.7
- Unit test passed.
v0.1.8
- Add _pooling_is_connection_closed test.
v0.1.9
- Fix doing useless time.sleep problem in pooling.mysql.MysqlConnectionPoolBase.get_session.
- Add pooling.mysql.PyMySQLConnectionPool.
v0.1.10
- Fix PoolBase.return_session double called in
with pool.get_session() as session: pass. - PoolBase add ping_test support.
v0.1.11
- Doc update.
v0.1.12
- Doc update.
Metadata
Release files for pooling 0.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pooling-0.1.12.tar.gz | 7.5 kB | Without provenance | Details for pooling-0.1.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pooling-0.1.12-py3-none-any.whl | Python 3 | none | any | Details for pooling-0.1.12-py3-none-any.whl |
Total release size: 15.0 kB
Release files / pooling-0.1.12.tar.gz
| Download URL | pooling-0.1.12.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d25dd59ba43e70ffe23abf89d11b0e254e6e26982bfaffbff0d90f48bbe4a1f
|
|
BLAKE2b-256 checksum How to use checksums |
536d587403253cdcfb0133eccdbe29a716c101f1a6464a12c3fd1e44988b1816
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Release files / pooling-0.1.12-py3-none-any.whl
| Download URL | pooling-0.1.12-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92066544c5388c7401d5f6cb709f98e4e899bf46e2e58840995bc1b3e180533e
|
|
BLAKE2b-256 checksum How to use checksums |
92ad6008ceca43bc5bc92eb79941576a76c62664bbf5e8aaa362d40e8cb9d7c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Security for pooling 0.1.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.