Skip to content
Browse files

Fixed #17251 -- In the select_for_update tests, close manually databa…

…se connections made in threads, so they don't stay "idle in transaction" until the GC deletes them. Thanks Anssi Kääriäinen for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17195 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 219b41c commit 545c3159f57ca110f1b60f1f82b672a3a1b95b2c @aaugustin aaugustin committed
Showing with 10 additions and 1 deletion.
  1. +10 −1 tests/modeltests/select_for_update/tests.py
View
11 tests/modeltests/select_for_update/tests.py
@@ -155,7 +155,7 @@ def run_select_for_update(self, status, nowait=False):
Person instances. After the select_for_update, it attempts
to update the name of the only record, save, and commit.
- In general, this will be run in a separate thread.
+ This function expects to run in a separate thread.
"""
status.append('started')
try:
@@ -173,6 +173,10 @@ def run_select_for_update(self, status, nowait=False):
status.append(e)
except Exception, e:
raise
+ finally:
+ # This method is run in a separate thread. It uses its own
+ # database connection. Close it without waiting for the GC.
+ connection.close()
@requires_threading
@skipUnlessDBFeature('has_select_for_update')
@@ -244,6 +248,11 @@ def raw(status):
)
except DatabaseError, e:
status.append(e)
+ finally:
+ # This method is run in a separate thread. It uses its own
+ # database connection. Close it without waiting for the GC.
+ connection.close()
+
status = []
thread = threading.Thread(target=raw, kwargs={'status': status})
thread.start()

0 comments on commit 545c315

Please sign in to comment.
Something went wrong with that request. Please try again.