summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2020-05-27 09:44:01 -0500
committerGitHub <noreply@github.com>2020-05-27 09:44:01 -0500
commit1a4d1a98f85896b1fea2c1ec3bd728ccc6ab5010 (patch)
tree8393a5b65fb56285cd601ef9b81c348c82afff3a
parent51f411aed0806ac7e84ad84b26062efac51951d7 (diff)
parent7a03297cdded8b6d55f8242aed40cfbdad8e0fc0 (diff)
downloadwaitress-1a4d1a98f85896b1fea2c1ec3bd728ccc6ab5010.tar.gz
Merge pull request #302 from Pylons/fix/thread_name
Fix: thread name
-rw-r--r--CHANGES.txt6
-rw-r--r--src/waitress/task.py8
-rw-r--r--tests/test_task.py4
3 files changed, 13 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index c40246b..b2076cd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -9,6 +9,12 @@ Unreleased
See https://github.com/Pylons/waitress/pull/300
+- Waitress threads have been updated to contain their thread number. This will
+ allow loggers that use that information to print the thread that the log is
+ coming from.
+
+ See https://github.com/Pylons/waitress/pull/302
+
1.4.3 (2020-02-02)
------------------
diff --git a/src/waitress/task.py b/src/waitress/task.py
index 8e7ab18..6350e34 100644
--- a/src/waitress/task.py
+++ b/src/waitress/task.py
@@ -57,8 +57,10 @@ class ThreadedTaskDispatcher(object):
self.queue_cv = threading.Condition(self.lock)
self.thread_exit_cv = threading.Condition(self.lock)
- def start_new_thread(self, target, args):
- t = threading.Thread(target=target, name="waitress", args=args)
+ def start_new_thread(self, target, thread_no):
+ t = threading.Thread(
+ target=target, name="waitress-{}".format(thread_no), args=(thread_no,)
+ )
t.daemon = True
t.start()
@@ -96,7 +98,7 @@ class ThreadedTaskDispatcher(object):
thread_no = thread_no + 1
threads.add(thread_no)
running += 1
- self.start_new_thread(self.handler_thread, (thread_no,))
+ self.start_new_thread(self.handler_thread, thread_no)
self.active_count += 1
thread_no = thread_no + 1
if running > count:
diff --git a/tests/test_task.py b/tests/test_task.py
index 1a86245..6466823 100644
--- a/tests/test_task.py
+++ b/tests/test_task.py
@@ -34,7 +34,7 @@ class TestThreadedTaskDispatcher(unittest.TestCase):
L = []
inst.start_new_thread = lambda *x: L.append(x)
inst.set_thread_count(1)
- self.assertEqual(L, [(inst.handler_thread, (0,))])
+ self.assertEqual(L, [(inst.handler_thread, 0)])
def test_set_thread_count_increase_with_existing(self):
inst = self._makeOne()
@@ -42,7 +42,7 @@ class TestThreadedTaskDispatcher(unittest.TestCase):
inst.threads = {0}
inst.start_new_thread = lambda *x: L.append(x)
inst.set_thread_count(2)
- self.assertEqual(L, [(inst.handler_thread, (1,))])
+ self.assertEqual(L, [(inst.handler_thread, 1)])
def test_set_thread_count_decrease(self):
inst = self._makeOne()