jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/481121 )
Change subject: atexit: Stop polluting stdout with sys.last_type
......................................................................
atexit: Stop polluting stdout with sys.last_type
Some people (eg. me) use more of pywikibot as a library, and in some
uses, like text stream processors, stdio pollution is simply not
tolerable.
Besides, sys.last_type should already be given, at exit time, by
sys.excepthook, to stderr. There is no reason whatsoever the cause
of exit should be duplicated to stdout when it's already in stderr.
In the extreme case that a user actually rely on this bug feature
(I can't imagine why but it's possible, given this code has existed
for so long that I finally hit some use case that can't tolerate
this anymore), it's very easy for them to register their own atexit
handler; on the other hand, it's very hard for me to silent this
atexit handler without directly removing the line.
This is so bad that we even had to create an exception for T001 in
tox.ini without any explanation why this print must exist in the
first place.
Oh and in case anyone wonders, this print was added almost 5 years
ago in 4b09153, and in that diff it looks more like for debugging
or testing of that patch rather than something critical.
Considering that the logged messages at exit may be the same (except
the log level of 'Closing network session.'), the exception type is
now logged in a more meaningful message in critical log level and
the original 'Closing network session.' is now always info level,
since it is the exception, not the network session being closed,
that is of interest to the user.
Change-Id: I83ce680f7e4eeb2e18fcfc60db70e88a8c668538
---
M pywikibot/comms/http.py
M tox.ini
2 files changed, 3 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 893942e..fc9b369 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -119,14 +119,11 @@
# Prepare flush on quit
def _flush():
+ log('Closing network session.')
session.close()
- message = 'Closing network session.'
+
if hasattr(sys, 'last_type'):
- # we quit because of an exception
- print(sys.last_type)
- critical(message)
- else:
- log(message)
+ critical('Exiting due to uncaught exception {}'.format(sys.last_type))
log('Network session closed.')
diff --git a/tox.ini b/tox.ini
index 68da0e9..506146b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -150,7 +150,6 @@
pywikibot/_wbtypes.py: N802
pywikibot/backports.py: N802
pywikibot/bot.py: N802
- pywikibot/comms/http.py : T001
pywikibot/compat/catlib.py : N803
pywikibot/compat/query.py: N802
pywikibot/cosmetic_changes.py : N803, N806, N802
--
To view, visit
https://gerrit.wikimedia.org/r/481121
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: I83ce680f7e4eeb2e18fcfc60db70e88a8c668538
Gerrit-Change-Number: 481121
Gerrit-PatchSet: 3
Gerrit-Owner: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)