jenkins-bot merged this change.

View Change

Approvals: jenkins-bot: Verified Framawiki: Looks good to me, approved
[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(-)

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)



To view, visit change 443849. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I97959f9d59a67439cd4ea8ac89a4980cd5d093b4
Gerrit-Change-Number: 443849
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: Dvorapa <dvorapa@seznam.cz>