jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved Count Count: Looks good to me, but someone else must approve jenkins-bot: Verified
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(-)

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 change 525179. To unsubscribe, or for help writing mail filters, visit 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@gmail.com>
Gerrit-Reviewer: Count Count <countvoncount123456@gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)