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 <[email protected]>
Gerrit-Reviewer: Count Count <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: Dvorapa <[email protected]>
Gerrit-Reviewer: Framawiki <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: Zhuyifei1999 <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to