On Thursday, April 19, 2012 7:08:06 PM UTC-4, Ricardo Pedroso wrote:
> I post a comment on this issue:
> http://code.google.com/p/web2py/issues/detail?id=731#c4
>
> I think this is not a bug but an incorrect use of the dal api.
>
Ricardo, thanks! That is indeed the problem. Whether or not it is a misuse
of the API, the API that I actually need (cleanly close only SOME
dal/adapter instances and not ALL dal/adapter instances) does not currently
exist, and I need to to reach into the underlying implementation to do what
I want.
For massimo: something like the following might be useful (note: untested):
(added to ConnectionPool class)
def close_or_recycle(self, action):
""" to close cleanly in a multithreaded environment """
if self in thread.get(instances, []):
if action:
if callable(action):
action(self)
else:
getattr(self, action)()
# ## if you want pools, recycle this connection
really = True
if self.pool_size:
sql_locker.acquire()
pool = ConnectionPool.pools[self.uri]
if len(pool) < self.pool_size:
pool.append(self.connection)
really = False
sql_locker.release()
if really:
self.close()
if callable(action):
action(None)
return
and rewriting close_all_instances to use this while popping
thread.instances on one hand, and having a DAL.close() method which calls
self._adapter.close_or_recycle() (possibly also from DAL.__del__)
Thanks!