Giter Club home page Giter Club logo

cuttlepool's People

Contributors

nuuk42 avatar spenceforce avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

nuuk42

cuttlepool's Issues

Improper use of RLock

Currently RLock is instantiated every time it is needed. The proper usage is for a connection pool object to have one RLock object that handles all locking instead.

Clean up tests

Test public API and use environment variables to determine which type of sql to use.

Internally track connections?

Keep references to all connections in CuttlePool object whether they are in the queue or not?

Would make it easier to prevent improper things being passed in and would simplify dealing with the size increments/decrements.

Reset cursor class on connection

A connection's cursor class can be modified when out and about which can cause undesired behavior when it is later retrieved from the pool as it will be expected to create regular cursors but will not. When it's returned to the CuttlePool object it's cursorclass attribute should be set to the base cursor class.

Race-Condition

The class CuttlePool has a race-condition in its method get_resource.

Setup:

  • the pool contains one available resource
  • no resources are in use
  • two threads are using the pool

Sequence of events:

  1. thread-1:: calls "get_resource"
  2. thread-1:: the method "_get()" returns the object "_ResourceTracker-1" and move this
    object to the part of the "_reference_queue" that contains the resources that
    are in use.
  3. thread-1:: calls "self.ping" using the resource from "_ResourceTracker-1" as argument.
    Note: at this point in time a call to the method "available()" of the object
    "_ResourceTracker-1" returns "True" because the "weakref" to the wraped resource
    has not yet been established. This happens later in "get_resource" with a call to
    the method "wrap_resource".
  4. thread-2:: calls "get_resource"
  5. thread-2:: The pool's "empty()" return "True" and so "_harvest_lost_resources" is called to look
    for resources that haven been properly returned to pool.
  6. thread-2:: "_harvest_lost_resources" loops the part of the "_reference_queue" that contains the
    "_ResourceTracker" objects of resources that are in use. It finds "_ResourceTracker-1"
    and calls the "available" method which returns "True".
    The method "_harvest_lost_resources" then returns the object "_ResourceTracker-1" to the
    part of the "_reference_queue" that contains the available resources.
  7. thread-2:: The method "_get()" returns "_ResourceTracker-1"

As a result, boths thread are using the same resource.

Clean up bare exceptions

There are a few bare exceptions like:

try:
    ...
except:  # bare exception
    ...

These should catch more specific exceptions.

the attribute of the sqlite3 which is "check_same_thread" not supporting?

I want to use the cuttlepool in multi thread envrionment, but it seems that it doesn't support the option of the sqlite3 ,"check_same_thread : False" .
Am I wrong or Do I have to look for other libraries?
self.pool = SQLitePool(factory=sqlite3.connect,capacity=4,database='/mnt/config/test.db',isolation_level=None,check_same_thread=False)

It is not working at all

Fix tutorial paragraph about `normalize_connection()`

Here's the paragraph:

CuttlePool is imported and subclassed. The normalize_connection() method takes a Connection object as a parameter and changes it's properties. This is important because a Connection object can be modified while it's outside of the pool and any modifications made during that time

The final sentence is unfinished.

Use ping instead of try/except in _close_connection.

Using ping will check if the connection is open and it moves the burden of proper exception handling to the user. It's impossible to determine the user's needs given any SQL driver so it's best left to them to decide what's best. Related to #21

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.