jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/443849 )
Change subject: [IMPR] Allow terminating the bot generator ......................................................................
[IMPR] Allow terminating the bot generator
- Introduce BaseBot.stop which raises a GeneratorExit exception to allow the BaseBot.generator to be stopped in such cases if generator.close() is not available. - Let BaseBot.run recognize the GeneratorExit exception to stop the loop. - Use the stop method in redirect.py
Bug: T198801 Change-Id: I97959f9d59a67439cd4ea8ac89a4980cd5d093b4 --- M pywikibot/bot.py M scripts/redirect.py 2 files changed, 7 insertions(+), 1 deletion(-)
Approvals: jenkins-bot: Verified Framawiki: Looks good to me, approved
diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 51ad1bc..de27fe0 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -1363,6 +1363,10 @@ return True return False
+ def stop(self): + """Stop iterating.""" + raise GeneratorExit + def quit(self): """Cleanup and quit processing.""" raise QuitKeyboardInterrupt @@ -1512,6 +1516,8 @@ % (self.__class__.__name__, sys.maxint)) else: self._generator_completed = True + except GeneratorExit: + pywikibot.output('Generator has been stopped.') except QuitKeyboardInterrupt: pywikibot.output('\nUser quit %s bot run...' % self.__class__.__name__) diff --git a/scripts/redirect.py b/scripts/redirect.py index baa6286..3d6fd2f 100755 --- a/scripts/redirect.py +++ b/scripts/redirect.py @@ -711,7 +711,7 @@ if self._treat_counter >= self.getOption('total'): pywikibot.output('\nNumber of pages reached the total limit. ' 'Script terminated.') - self.quit() + self.stop() super(RedirectRobot, self).treat(page)