summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-09-11 18:52:34 +0200
committerAurélien Bompard <aurelien@bompard.org>2012-09-11 18:52:37 +0200
commit091f625967dd4f5f6a32b7f1d7a2d8319e7c8746 (patch)
treee4fbfeccafb5ca720d0f16f08e30f4f8a7551b29
parent2bf1a119ddab23219d965953be87ce77088cadea (diff)
downloadkittystore-091f625967dd4f5f6a32b7f1d7a2d8319e7c8746.tar.gz
kittystore-091f625967dd4f5f6a32b7f1d7a2d8319e7c8746.tar.xz
kittystore-091f625967dd4f5f6a32b7f1d7a2d8319e7c8746.zip
Use a middleware in HK to avoid connection leaks
The middleware also handle thread-safety issues
-rw-r--r--kittystore/storm/__init__.py27
-rw-r--r--kittystore/storm/store.py7
2 files changed, 22 insertions, 12 deletions
diff --git a/kittystore/storm/__init__.py b/kittystore/storm/__init__.py
index 8174e55..da1a56d 100644
--- a/kittystore/storm/__init__.py
+++ b/kittystore/storm/__init__.py
@@ -31,20 +31,23 @@ class ThreadSafeStorePool(object):
try:
return self._local.store
except AttributeError:
- self._local.store = self.create_store()
+ self._local.store = create_store(self.url, self.debug)
return self._local.store
- def create_store(self):
- if self.debug:
- storm.tracer.debug(True, stream=sys.stdout)
- database = create_database(self.url)
- store = Store(database)
- dbtype = self.url.partition(":")[0]
- dbschema = Schema(schema.CREATES[dbtype], [], [], schema)
- dbschema.upgrade(store)
- return StormStore(store, self.debug)
+
+def create_store(url, debug):
+ if debug:
+ storm.tracer.debug(True, stream=sys.stdout)
+ database = create_database(url)
+ store = Store(database)
+ dbtype = url.partition(":")[0]
+ dbschema = Schema(schema.CREATES[dbtype], [], [], schema)
+ dbschema.upgrade(store)
+ return StormStore(store, debug)
def get_storm_store(url, debug=False):
- store_pool = ThreadSafeStorePool(url, debug)
- return store_pool.get()
+ # Thread safety is managed by the middleware
+ #store_pool = ThreadSafeStorePool(url, debug)
+ #return store_pool.get()
+ return create_store(url, debug)
diff --git a/kittystore/storm/store.py b/kittystore/storm/store.py
index 0c5b91e..8bb3872 100644
--- a/kittystore/storm/store.py
+++ b/kittystore/storm/store.py
@@ -366,3 +366,10 @@ class StormStore(object):
def commit(self):
"""Commit transaction to the database."""
self.db.commit()
+
+ def close(self):
+ """Close the connection."""
+ self.db.close()
+
+ def rollback(self):
+ self.db.rollback()