jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/701685 )
Change subject: [fix] Replace deprecated threading functions and methods
......................................................................
[fix] Replace deprecated threading functions and methods
Bug: T285621
Change-Id: I4c2cde8564aa7f239e34753b0a719e676246daa9
---
M pywikibot/__init__.py
M pywikibot/tools/__init__.py
M scripts/archive/imagecopy.py
M scripts/archive/wikisourcetext.py
M scripts/weblinkchecker.py
M tests/site_tests.py
6 files changed, 15 insertions(+), 20 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index deaec89..cc8ab20 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -1348,10 +1348,9 @@
# queue to signal that async_manager is working on a request. See T147178.
page_put_queue_busy = Queue(_config.max_queue_size)
# set up the background thread
-_putthread = threading.Thread(target=async_manager)
-# identification for debugging purposes
-_putthread.setName('Put-Thread')
-_putthread.setDaemon(True)
+_putthread = threading.Thread(target=async_manager,
+ name='Put-Thread', # for debugging purposes
+ daemon=True)
wrapper = _ModuleDeprecationWrapper(__name__)
wrapper.add_deprecated_attr('config2',
replacement_name='pywikibot.config',
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 40c7f29..dd9969a 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -764,7 +764,7 @@
if not self.is_alive() and not self.finished.isSet():
self.start()
# if there is an item in the queue, yield it, otherwise wait
- while not self.finished.isSet():
+ while not self.finished.is_set():
try:
yield self.queue.get(True, 0.25)
except queue.Empty:
@@ -786,7 +786,7 @@
self.__gen = self.generator(*self.args, **self.kwargs)
for result in self.__gen:
while True:
- if self.finished.isSet():
+ if self.finished.is_set():
return
try:
self.queue.put_nowait(result)
@@ -795,7 +795,7 @@
continue
break
# wait for queue to be emptied, then kill the thread
- while not self.finished.isSet() and not self.queue.empty():
+ while not self.finished.is_set() and not self.queue.empty():
time.sleep(0.25)
self.stop()
diff --git a/scripts/archive/imagecopy.py b/scripts/archive/imagecopy.py
index fb29031..dabf880 100755
--- a/scripts/archive/imagecopy.py
+++ b/scripts/archive/imagecopy.py
@@ -574,10 +574,10 @@
imageTransfer(imagepage, newname, category,
delete_after_done).start()
- pywikibot.output('Still ' + str(threading.activeCount())
+ pywikibot.output('Still ' + str(threading.active_count())
+ ' active threads, lets wait')
for openthread in threading.enumerate():
- if openthread != threading.currentThread():
+ if openthread != threading.current_thread():
openthread.join()
pywikibot.output('All threads are done')
diff --git a/scripts/archive/wikisourcetext.py b/scripts/archive/wikisourcetext.py
index 5fd7f99..cc6f813 100755
--- a/scripts/archive/wikisourcetext.py
+++ b/scripts/archive/wikisourcetext.py
@@ -123,8 +123,7 @@
def _spawn_ocr_threads(self):
"""Spawn threads for _ocr_worker workers."""
for i in range(self._num_threads):
- worker = threading.Thread(target=self._ocr_worker)
- worker.setDaemon(True)
+ worker = threading.Thread(target=self._ocr_worker, daemon=True)
worker.start()
self._pages = collections.OrderedDict()
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py
index 9580710..e37b8fd 100755
--- a/scripts/weblinkchecker.py
+++ b/scripts/weblinkchecker.py
@@ -288,7 +288,6 @@
def __init__(self, page, url, history, HTTPignore, day):
"""Initializer."""
- super().__init__()
self.page = page
self.url = url
self.history = history
@@ -301,13 +300,14 @@
'Connection': 'keep-alive',
}
# identification for debugging purposes
- self.setName(('{} - {}'.format(page.title(),
- url.encode('utf-8', 'replace'))))
self.HTTPignore = HTTPignore
self._use_fake_user_agent = config.fake_user_agent_default.get(
'weblinkchecker', False)
self.day = day
+ name = '{} - {}'.format(page.title(), url.encode('utf-8',
'replace'))
+ super().__init__(name=name)
+
def run(self):
"""Run the bot."""
try:
@@ -570,8 +570,6 @@
if config.report_dead_links_on_talk:
pywikibot.log('Starting talk page thread')
reportThread = DeadLinkReportThread()
- # thread dies when program terminates
- # reportThread.setDaemon(True)
reportThread.start()
else:
reportThread = None
@@ -595,7 +593,7 @@
thread = LinkCheckThread(page, url, self.history,
self.HTTPignore, self.day)
# thread dies when program terminates
- thread.setDaemon(True)
+ thread.daemon = True
self.threads.append(thread)
diff --git a/tests/site_tests.py b/tests/site_tests.py
index f3ecc14..56a9789 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -928,15 +928,14 @@
# Start few threads
threads = []
for _ in range(5):
- thread = threading.Thread(target=self.worker)
- thread.setDaemon(True)
+ thread = threading.Thread(target=self.worker, daemon=True)
thread.start()
threads.append(thread)
for thread in threads:
thread.join(15) # maximum wait time for all threads
- with self.subTest(name=thread.getName()):
+ with self.subTest(name=thread.name):
# Check whether a timeout happened.
# In that case is_alive() is True
self.assertFalse(thread.is_alive(),
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/701685
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I4c2cde8564aa7f239e34753b0a719e676246daa9
Gerrit-Change-Number: 701685
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-MessageType: merged