Ticket #4284 defect reopened
t.e.adbapi leaks threads if you don't explicitly call .close()
| Reported by: | dustin | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | core | Keywords: | doc enterprise adbapi |
| Cc: | zooko@… | Branch: | |
| Author: | Launchpad Bug: |
Description
My project is using sqlite3 via adbapi, so the unit tests create a lot of "test" databases that are immediately destroyed.
These tests started failing with resource-exhaustion errors -- MemoryError or "can't start new thread" -- so I went hunting for a thread leak. I narrowed the search down to adbapi, and then to the threadpool. This is in Twisted-9.0.0. The failing test is
import threading
from twisted.python import threadpool
from twisted.internet import threads
from twisted.trial import unittest
class t(unittest.TestCase):
def setUp(self):
self.pool = threadpool.ThreadPool(3, 5)
self.pool.start()
def tearDown(self):
print list(threading.enumerate())
def testit(self):
from twisted.internet import reactor
return threads.deferToThreadPool(reactor, self.pool, lambda : True)
def testit2(self):
return self.testit()
def testit3(self):
return self.testit()
def testit4(self):
return self.testit()
def testit5(self):
return self.testit()
def testit6(self):
return self.testit()
def testit7(self):
return self.testit()
def testit8(self):
return self.testit()
This shows that the number of extant threads is increasing by 3 for each test.
I've seen this under Python 2.4-2.6. I've only tried Twisted-9.0.0, so I don't know if this is a regression or not.
Change History
Note: See
TracTickets for help on using
tickets.
