django-orchestra/orchestra/utils/db.py
2015-05-05 19:42:55 +00:00

16 lines
385 B
Python

from django import db
def close_connection(execute):
""" Threads have their own connection pool, closing it when finishing """
def wrapper(*args, **kwargs):
try:
log = execute(*args, **kwargs)
except Exception as e:
pass
else:
wrapper.log = log
finally:
db.connection.close()
return wrapper