Replace deprecated Thread.getName() and Condition.notifyAll()

This commit is contained in:
Chris Mayo 2021-11-16 19:45:38 +00:00
parent 57a1234b49
commit 2a77e12618
5 changed files with 9 additions and 10 deletions

View file

@ -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

View file

@ -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."""

View file

@ -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):

View file

@ -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()

View file

@ -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)