#4284 defect reopened
t.e.adbapi leaks threads if you don't explicitly call .close()
|Reported by:||dustin||Owned by:|
|Component:||core||Keywords:||doc enterprise adbapi|
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 (4)
comment:1 Changed 4 years ago by dustin
- Resolution set to invalid
- Status changed from new to closed
- Summary changed from t.p.threadpool leaks threads to t.e.adbapi leaks threads
comment:2 Changed 4 years ago by zooko
- Cc zooko@… added
- Keywords doc enterprise adbapi added
- Resolution invalid deleted
- Status changed from closed to reopened
- Summary changed from t.e.adbapi leaks threads to t.e.adbapi leaks threads if you don't explicitly call .close()