kgaughan / dbkit

Taking some of the pain out of Python's DB-API
MIT License
6 stars 2 forks source link

A connection pool for type 1 drivers #12

Open kgaughan opened 12 years ago

kgaughan commented 12 years ago

The reason for this is SQLite support. I'm not sure how exactly I'll end up implementing this as the thread affinity involved is a touch more awkward to deal with than with type 2 and type 3 drivers, which the existing connection pool handles just fine.

kgaughan commented 12 years ago

Some kind of threadlocal storage would be ideal, but we need to trap when the thread exits.

kgaughan commented 12 years ago

Getting there. Punting the issue with threads exiting to weak references. ThreadAffinePool needs testing though.

kgaughan commented 12 years ago

Turns out the sqlite3 driver doesn't like weak references being used with its connections. Weak. I've switched to using strong references for it. This does not make me happy. Also added DummyPool, which is specifically meant for type 0 drivers where it forces a single connection at a time, but will allow multiple connections with more capable drivers.

kgaughan commented 11 years ago

ThreadAffinePool has been nixed for the moment: it has race conditions.

When using DummyPool with the sqlite3 driver module and waitress, I'm getting "ProgrammingError: Cannot operate on a closed database" as an exception. My guess is that this is some kind of race condition, and it may affect Pool in some way that I don't know about (even though it appears to work just fine).

kgaughan commented 11 years ago

Still can't get type 1 driver support right, so I'm removing it and maybe creating a separate branch.