jenkins-bot has submitted this change and it was merged.
Change subject: Safer ctrl-c handling. ......................................................................
Safer ctrl-c handling.
This prevents half-finished changes to be written to Wikidata. Instead, this finished the current change and then exits.
Change-Id: Iac27f7f7ddc7578368fa149e4be136bb0f9b12ef --- M scripts/harvest_template.py 1 file changed, 17 insertions(+), 0 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py index 8c60ba6..ec5fc3b 100755 --- a/scripts/harvest_template.py +++ b/scripts/harvest_template.py @@ -35,6 +35,21 @@ #
import re +import signal + +willstop = False + + +def _signal_handler(signal, frame): + global willstop + if not willstop: + willstop = True + print("Received ctrl-c. Finishing current item; press ctrl-c again to abort.") + else: + raise KeyboardInterrupt + +signal.signal(signal.SIGINT, _signal_handler) + import pywikibot from pywikibot import pagegenerators as pg, textlib, WikidataBot
@@ -111,6 +126,8 @@
def treat(self, page, item): """Process a single page/item.""" + if willstop: + raise KeyboardInterrupt self.current_page = page item.get() if set(self.fields.values()) <= set(item.claims.keys()):
pywikibot-commits@lists.wikimedia.org