jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/542765 )
Change subject: site_tests.py: Only threads started by the test for test_lock_page
......................................................................
site_tests.py: Only threads started by the test for test_lock_page
There are threads like 'Put-Thread' that are alive and has nothing
to do with our deadlock.
Change-Id: Id79c61599ac3df9ae8781da5ff5a0d16553f1d43
---
M tests/site_tests.py
1 file changed, 3 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 58a8a3b..c7ff572 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1106,15 +1106,14 @@
def test_lock_page(self):
"""Test the site.lock_page() and site.unlock_page() method."""
# Start few threads
+ threads = []
for i in range(5):
thread = threading.Thread(target=self.worker)
thread.setDaemon(True)
thread.start()
+ threads.append(thread)
- current_thread = threading.currentThread()
- for thread in threading.enumerate():
- if thread is current_thread:
- continue
+ for thread in threads:
thread.join(15) # maximum wait time for all threads
with self.subTest(name=thread.getName()):
--
To view, visit https://gerrit.wikimedia.org/r/542765
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id79c61599ac3df9ae8781da5ff5a0d16553f1d43
Gerrit-Change-Number: 542765
Gerrit-PatchSet: 1
Gerrit-Owner: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/542438 )
Change subject: [tests] Tests for log_page/unlock_page implementation
......................................................................
[tests] Tests for log_page/unlock_page implementation
- Add a test class to test whether log_page/unlock_page works
successfull with threads or detect deadlocks.
If a deadlock is detected a timeout occures with a thread
and is_alive() is True in that case.
tests detached from I1ff2c39
Change-Id: I83b2de3378ef1b7c9f2ab0852a37a7511bc6c40c
---
M tests/site_tests.py
1 file changed, 37 insertions(+), 0 deletions(-)
Approvals:
Zhuyifei1999: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 306ea27..58a8a3b 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -9,14 +9,17 @@
import os
import pickle
+import random
import re
import sys
+import time
try:
from collections.abc import Iterable, Mapping
except ImportError: # Python 2.7
from collections import Iterable, Mapping
from datetime import datetime
+import threading
import pywikibot
@@ -1087,6 +1090,40 @@
self.assertRaises(AssertionError, func, 'm', 2, 1, True, True)
+class TestThreadsLockingPage(DefaultSiteTestCase):
+ """Test cases for lock/unlock a page within threads."""
+
+ cached = True
+
+ def worker(self):
+ """Lock a page, wait few seconds and unlock the page."""
+ page = pywikibot.Page(self.site, 'Foo')
+ page.site.lock_page(page=page, block=True)
+ wait = random.randint(1, 25) / 10
+ time.sleep(wait)
+ page.site.unlock_page(page=page)
+
+ def test_lock_page(self):
+ """Test the site.lock_page() and site.unlock_page() method."""
+ # Start few threads
+ for i in range(5):
+ thread = threading.Thread(target=self.worker)
+ thread.setDaemon(True)
+ thread.start()
+
+ current_thread = threading.currentThread()
+ for thread in threading.enumerate():
+ if thread is current_thread:
+ continue
+ thread.join(15) # maximum wait time for all threads
+
+ with self.subTest(name=thread.getName()):
+ # Check whether a timeout happened.
+ # In that case is_alive() is True
+ self.assertFalse(thread.is_alive(),
+ 'test page is still locked')
+
+
class TestSiteGeneratorsUsers(DefaultSiteTestCase):
"""Test cases for Site methods with users."""
--
To view, visit https://gerrit.wikimedia.org/r/542438
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I83b2de3378ef1b7c9f2ab0852a37a7511bc6c40c
Gerrit-Change-Number: 542438
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/525179 )
Change subject: site.py: lock_page release mutex during sleep
......................................................................
site.py: lock_page release mutex during sleep
Otherwise nobody can possibly unlock it....
Change-Id: Iba518656c9334455bb71d68f93c11a57863a5671
---
M pywikibot/site.py
1 file changed, 19 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
Count Count: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index dabdf05..9a200e9 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1072,15 +1072,30 @@
otherwise, raise an exception if page can't be locked
"""
+ title = page.title(with_section=False)
+
self._pagemutex.acquire()
try:
- while page.title(with_section=False) in self._locked_pages:
+ while title in self._locked_pages:
if not block:
- raise PageInUse(page.title(with_section=False))
+ raise PageInUse(title)
+
+ # The mutex must be released so that page can be unlocked
+ self._pagemutex.release()
time.sleep(.25)
- self._locked_pages.append(page.title(with_section=False))
+ self._pagemutex.acquire()
+
+ self._locked_pages.append(title)
finally:
- self._pagemutex.release()
+ # time.sleep may raise an exception from signal handler (eg:
+ # KeyboardInterrupt) while the lock is released, and there is no
+ # reason to acquire the lock again given that our caller will
+ # receive the exception. The state of the lock is therefore
+ # undefined at the point of this finally block.
+ try:
+ self._pagemutex.release()
+ except RuntimeError:
+ pass
def unlock_page(self, page):
"""
--
To view, visit https://gerrit.wikimedia.org/r/525179
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iba518656c9334455bb71d68f93c11a57863a5671
Gerrit-Change-Number: 525179
Gerrit-PatchSet: 6
Gerrit-Owner: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Count Count <countvoncount123456(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/540854 )
Change subject: [IMPR] Improvements for askForHints (3)
......................................................................
[IMPR] Improvements for askForHints (3)
- decrease nested code
Change-Id: I8aea761ed32046fd843e734205479ac1989f84d9
---
M scripts/interwiki.py
1 file changed, 31 insertions(+), 29 deletions(-)
Approvals:
D3r1ck01: Looks good to me, but someone else must approve
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 36bcc7f..e9c6264 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -1170,43 +1170,45 @@
if not self.workonme: # we don't work on it anyway
return
- if ((self.untranslated or self.conf.askhints)
+ if not (
+ (self.untranslated or self.conf.askhints)
and not self.hintsAsked
and self.originPage
and self.originPage.exists()
and not self.originPage.isRedirectPage()
and not self.originPage.isCategoryRedirect()):
+ return
- self.hintsAsked = True
- if not self.conf.untranslated:
- return
+ self.hintsAsked = True
+ if not self.conf.untranslated:
+ return
- t = self.conf.showtextlink
- if t:
+ t = self.conf.showtextlink
+ if t:
+ pywikibot.output(self.originPage.get()[:t])
+
+ while True:
+ newhint = pywikibot.input('Give a hint (? to see pagetext):')
+ if not newhint:
+ break
+ if newhint == '?':
+ t += self.conf.showtextlinkadd
pywikibot.output(self.originPage.get()[:t])
-
- while True:
- newhint = pywikibot.input('Give a hint (? to see pagetext):')
- if not newhint:
- break
- if newhint == '?':
- t += self.conf.showtextlinkadd
- pywikibot.output(self.originPage.get()[:t])
- elif ':' not in newhint:
- pywikibot.output(fill(
- 'Please enter a hint in the format language:pagename '
- 'or type nothing if you do not have a hint.'))
- else:
- links = titletranslate.translate(
- self.originPage,
- hints=[newhint],
- auto=self.conf.auto,
- removebrackets=self.conf.hintnobracket)
- for link in links:
- page = pywikibot.Page(link)
- self.addIfNew(page, counter, None)
- if self.conf.hintsareright:
- self.hintedsites.add(page.site)
+ elif ':' not in newhint:
+ pywikibot.output(fill(
+ 'Please enter a hint in the format language:pagename '
+ 'or type nothing if you do not have a hint.'))
+ else:
+ links = titletranslate.translate(
+ self.originPage,
+ hints=[newhint],
+ auto=self.conf.auto,
+ removebrackets=self.conf.hintnobracket)
+ for link in links:
+ page = pywikibot.Page(link)
+ self.addIfNew(page, counter, None)
+ if self.conf.hintsareright:
+ self.hintedsites.add(page.site)
def batchLoaded(self, counter):
"""
--
To view, visit https://gerrit.wikimedia.org/r/540854
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I8aea761ed32046fd843e734205479ac1989f84d9
Gerrit-Change-Number: 540854
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: jenkins-bot (75)