Skip to content

lucidfrontier45/RethinkPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RethinkDB Connection Pool for Python

rethinkpool is a Python library for pooling RethinkDB connections. This is usefull for multi-thread application since a connection object Python driver provides is not thread-safe

Installation

$ pip install rethinkpool

Usage

Connection Pool can be created by instantiating RethinkPool.

from rethinkpool import RethinkPool

pool = RethinkPool()

The arguments for RethinkPool are as follows.

  • max_conns: maximum number of connections
  • initial_conns: number of initial connections to establish
  • get_timeout: timeout for obtaining a connection from the queue
  • host, port, ...: same as r.connect

The pooled ConnectionResource object can be obtained by pool.get_resource() Used connection resource can be returned to the pool as follows.

res = pool.get_resource()
cur = r.table("data").run(res.conn)
for obj in cur:
    print(obj)
res.release()

It also supports with statement for automatically restore used connection back to the pool.

with pool.get_resource() as res:
    cur = r.table("data").run(res.conn)
    for obj in cur:
        print(obj)

About

RethinkDB Connection Pool for Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages