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