Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to be slightly more accomodating of temporary thread leaks
- Loading branch information
Dustin J. Mitchell
committed
Aug 24, 2010
1 parent
cced0f5
commit 5fe0456
Showing
3 changed files
with
30 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import threading | ||
import time | ||
|
||
from twisted.python import log | ||
|
||
class ThreadLeakMixin(object): | ||
""" | ||
Monitor for leaking thread pools. Just call the setUp and tearDown methods! | ||
""" | ||
def setUpThreadLeak(self): | ||
self.start_thdcount = len(threading.enumerate()) | ||
|
||
def tearDownThreadLeak(self): | ||
# double-check we haven't left a ThreadPool open. Sometimes, threads | ||
# take a while to go away, so this will wait up to 5s for that to occur | ||
for time in xrange(5): | ||
cur_thdcount = len(threading.enumerate()) | ||
if cur_thdcount - self.start_thdcount < 1: | ||
return | ||
log.msg("threadcount: %d (start) %d (now)" % (self.start_thdcount, cur_thdcount)) | ||
time.sleep(1) | ||
self.fail("leaked %d threads" % (cur_thdcount - self.start_thdcount)) |