summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-07-06 13:25:15 -0400
committerChris McDonough <chrism@plope.com>2012-07-06 13:25:15 -0400
commite4051f87347c866f7d66399dc91315ab862fd411 (patch)
treeeafcc1f76ad7389b999db19eb4a89ed996aa1324
parente18bbfde117c8449cf67f9a3f14dd00b3cd93cd2 (diff)
downloadwaitress-fix.idemonkeys.tar.gz
- Appease IDEs that want to monkeypatch the thread module by changing afix.idemonkeys
testing pattern. With any luck, the following will no longer be a problem: http://devnet.jetbrains.net/thread/433486
-rw-r--r--CHANGES.txt9
-rw-r--r--waitress/task.py11
-rw-r--r--waitress/tests/test_task.py26
3 files changed, 32 insertions, 14 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 9091edc..ee8fddc 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,12 @@
+Next release
+------------
+
+- Add ``setup.py dev`` and ``setup.py docs`` aliases.
+
+- Appease IDEs that want to monkeypatch the thread module by changing a
+ testing pattern. With any luck, the following will no longer be a problem:
+ http://devnet.jetbrains.net/thread/433486
+
0.8.1 (2012-02-13)
------------------
diff --git a/waitress/task.py b/waitress/task.py
index 7d36817..5a256e1 100644
--- a/waitress/task.py
+++ b/waitress/task.py
@@ -55,9 +55,9 @@ class ThreadedTaskDispatcher(object):
"""A Task Dispatcher that creates a thread for each task.
"""
- stop_count = 0 # Number of threads that will stop soon.
- start_new_thread = thread.start_new_thread
- logger = logger
+ stop_count = 0 # Number of threads that will stop soon.
+ thread_module = thread # for testing
+ logger = logger # for testing
def __init__(self):
self.threads = {} # { thread number -> 1 }
@@ -101,7 +101,10 @@ class ThreadedTaskDispatcher(object):
thread_no = thread_no + 1
threads[thread_no] = 1
running += 1
- self.start_new_thread(self.handler_thread, (thread_no,))
+ self.thread_module.start_new_thread(
+ self.handler_thread,
+ (thread_no,)
+ )
thread_no = thread_no + 1
if running > count:
# Stop threads.
diff --git a/waitress/tests/test_task.py b/waitress/tests/test_task.py
index 1493b21..3d88cd2 100644
--- a/waitress/tests/test_task.py
+++ b/waitress/tests/test_task.py
@@ -29,19 +29,19 @@ class TestThreadedTaskDispatcher(unittest.TestCase):
def test_set_thread_count_increase(self):
inst = self._makeOne()
- L = []
- inst.start_new_thread = lambda *x: L.append(x)
+ mod = DummyThreadModule()
+ inst.thread_module = mod
inst.set_thread_count(1)
- self.assertEqual(L, [(inst.handler_thread, (0,))])
+ self.assertEqual(mod.threads, [(inst.handler_thread, (0,))])
def test_set_thread_count_increase_with_existing(self):
inst = self._makeOne()
- L = []
+ mod = DummyThreadModule()
+ inst.thread_module = mod
inst.threads = {0:1}
- inst.start_new_thread = lambda *x: L.append(x)
inst.set_thread_count(2)
- self.assertEqual(L, [(inst.handler_thread, (1,))])
-
+ self.assertEqual(mod.threads, [(inst.handler_thread, (1,))])
+
def test_set_thread_count_decrease(self):
inst = self._makeOne()
inst.threads = {'a':1, 'b':2}
@@ -51,11 +51,11 @@ class TestThreadedTaskDispatcher(unittest.TestCase):
def test_set_thread_count_same(self):
inst = self._makeOne()
- L = []
- inst.start_new_thread = lambda *x: L.append(x)
+ mod = DummyThreadModule()
+ inst.thread_module = mod
inst.threads = {0:1}
inst.set_thread_count(1)
- self.assertEqual(L, [])
+ self.assertEqual(mod.threads, [])
def test_add_task(self):
task = DummyTask()
@@ -684,3 +684,9 @@ class DummyLogger(object):
def exception(self, msg):
self.logged.append(msg)
+class DummyThreadModule(object):
+ def __init__(self):
+ self.threads = []
+ def start_new_thread(self, *x):
+ self.threads.append(x)
+