From 8dc7d8914305b4c3f434b1e6629d78c8a3dd317d Mon Sep 17 00:00:00 2001 From: Massimo Di Pierro Date: Sat, 7 Apr 2012 16:56:32 -0500 Subject: [PATCH] response.custom_commit patch, thanks Jonathan --- VERSION | 2 +- gluon/dal.py | 39 ++++++++++++++++++++++----------------- gluon/main.py | 6 ++++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/VERSION b/VERSION index 66ed7819..3a57ec80 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 1.99.7 (2012-04-07 16:53:28) dev +Version 1.99.7 (2012-04-07 16:56:18) dev diff --git a/gluon/dal.py b/gluon/dal.py index 24ab4e74..953da208 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -431,23 +431,28 @@ class ConnectionPool(object): @staticmethod def close_all_instances(action): """ to close cleanly databases in a multithreaded environment """ - if not hasattr(thread, 'instances'): - return - while thread.instances: - instance = thread.instances.pop() - if action: - getattr(instance, action)() - # ## if you want pools, recycle this connection - really = True - if instance.pool_size: - sql_locker.acquire() - pool = ConnectionPool.pools[instance.uri] - if len(pool) < instance.pool_size: - pool.append(instance.connection) - really = False - sql_locker.release() - if really: - getattr(instance, 'close')() + if hasattr(thread, 'instances'): + while thread.instances: + instance = thread.instances.pop() + if action: + if callable(action): + action(instance) + else: + getattr(instance, action)() + # ## if you want pools, recycle this connection + really = True + if instance.pool_size: + sql_locker.acquire() + pool = ConnectionPool.pools[instance.uri] + if len(pool) < instance.pool_size: + pool.append(instance.connection) + really = False + sql_locker.release() + if really: + getattr(instance, 'close')() + + if callable(action): + action(None) return def find_or_make_work_folder(self): diff --git a/gluon/main.py b/gluon/main.py index d613ea7c..8b99b7b9 100644 --- a/gluon/main.py +++ b/gluon/main.py @@ -515,8 +515,10 @@ def wsgibase(environ, responder): if response.do_not_commit is True: BaseAdapter.close_all_instances(None) - elif response._custom_commit: - response._custom_commit() + # elif response._custom_commit: + # response._custom_commit() + elif response.custom_commit: + BaseAdapter.close_all_instances(response.custom_commit) else: BaseAdapter.close_all_instances('commit')