Close database connection after lock access to keep this high call code from keeping too many open connections

This commit is contained in:
Roberto Rosario
2012-08-03 06:01:29 -04:00
parent 71c01670ac
commit da8eb2e508
2 changed files with 5 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ from __future__ import absolute_import
import logging
import datetime
from django.db import close_connection
from django.db.utils import IntegrityError
from django.db import transaction
from django.db import models
@@ -43,3 +44,5 @@ class LockManager(models.Manager):
else:
logger.debug('unable to acquire lock: %s' % name)
raise LockError('Unable to acquire lock')
finally:
close_connection()

View File

@@ -29,7 +29,6 @@ class Lock(models.Model):
@transaction.commit_on_success
def release(self):
close_connection()
try:
lock = Lock.objects.get(name=self.name, creation_datetime=self.creation_datetime)
lock.delete()
@@ -38,6 +37,8 @@ class Lock(models.Model):
pass
except DatabaseError:
transaction.rollback()
finally:
close_connection()
class Meta:
verbose_name = _(u'lock')