From 2a77e126181affca5e690592815371f91cab1c69 Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Tue, 16 Nov 2021 19:45:38 +0000 Subject: [PATCH] Replace deprecated Thread.getName() and Condition.notifyAll() --- linkcheck/cache/urlqueue.py | 4 ++-- linkcheck/director/aggregator.py | 7 +++---- linkcheck/director/checker.py | 2 +- linkcheck/lock.py | 4 ++-- linkcheck/trace.py | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/linkcheck/cache/urlqueue.py b/linkcheck/cache/urlqueue.py index 8bc00a87..61829901 100644 --- a/linkcheck/cache/urlqueue.py +++ b/linkcheck/cache/urlqueue.py @@ -185,7 +185,7 @@ class UrlQueue: if self.unfinished_tasks <= 0: if self.unfinished_tasks < 0: raise ValueError('task_done() called too many times') - self.all_tasks_done.notifyAll() + self.all_tasks_done.notify_all() def join(self, timeout=None): """Blocks until all items in the Queue have been gotten and processed. @@ -218,7 +218,7 @@ class UrlQueue: if unfinished <= 0: if unfinished < 0: raise ValueError('shutdown is in error') - self.all_tasks_done.notifyAll() + self.all_tasks_done.notify_all() self.unfinished_tasks = unfinished self.shutdown = True diff --git a/linkcheck/director/aggregator.py b/linkcheck/director/aggregator.py index 52400bcf..a9125696 100644 --- a/linkcheck/director/aggregator.py +++ b/linkcheck/director/aggregator.py @@ -168,7 +168,7 @@ class Aggregate: log.info(LOG_CHECK, name[12:]) args = dict( num=len( - [x for x in self.threads if x.getName().startswith("CheckThread-")] + [x for x in self.threads if x.name.startswith("CheckThread-")] ), timeout=strformat.strduration_long(self.config["aborttimeout"]), ) @@ -185,9 +185,8 @@ class Aggregate: def get_check_threads(self): """Return iterator of checker threads.""" for t in self.threads: - name = t.getName() - if name.startswith("CheckThread-"): - yield name + if t.name.startswith("CheckThread-"): + yield t.name def cancel(self): """Empty the URL queue.""" diff --git a/linkcheck/director/checker.py b/linkcheck/director/checker.py index 732326fb..f1e7c0a8 100644 --- a/linkcheck/director/checker.py +++ b/linkcheck/director/checker.py @@ -84,7 +84,7 @@ class Checker(task.LoggedCheckedTask): """Store URL queue and logger.""" super().__init__(logger) self.urlqueue = urlqueue - self.origname = self.getName() + self.origname = self.name self.add_request_session = add_request_session def run_checked(self): diff --git a/linkcheck/lock.py b/linkcheck/lock.py index 1f17ca14..e747872a 100644 --- a/linkcheck/lock.py +++ b/linkcheck/lock.py @@ -45,14 +45,14 @@ class DebugLock: def acquire(self, blocking=1): """Acquire lock.""" - threadname = threading.currentThread().getName() + threadname = threading.currentThread().name log.debug(LOG_THREAD, "Acquire %s for %s", self.name, threadname) self.lock.acquire(blocking) log.debug(LOG_THREAD, "...acquired %s for %s", self.name, threadname) def release(self): """Release lock.""" - threadname = threading.currentThread().getName() + threadname = threading.currentThread().name log.debug(LOG_THREAD, "Release %s for %s", self.name, threadname) self.lock.release() diff --git a/linkcheck/trace.py b/linkcheck/trace.py index 9fc4f2d4..e8dc8f44 100644 --- a/linkcheck/trace.py +++ b/linkcheck/trace.py @@ -77,7 +77,7 @@ def _trace_line(frame, event, arg): line = linecache.getline(filename, lineno) currentThread = threading.currentThread() tid = currentThread.ident - tname = currentThread.getName() + tname = currentThread.name args = (tid, tname, time.time(), line.rstrip(), name, lineno) print("THREAD(%d) %r %.2f %s # %s:%d" % args)