Skip to content

Commit

Permalink
Merge pull request #302 from Pylons/fix/thread_name
Browse files Browse the repository at this point in the history
Fix: thread name
  • Loading branch information
mmerickel authored May 27, 2020
2 parents 51f411a + 7a03297 commit 1a4d1a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

Expand Down
8 changes: 5 additions & 3 deletions src/waitress/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def __init__(self):
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()

Expand Down Expand Up @@ -96,7 +98,7 @@ def set_thread_count(self, count):
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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def test_set_thread_count_increase(self):
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()
L = []
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()
Expand Down

0 comments on commit 1a4d1a9

Please sign in to comment.