jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] Timeout session.requests
......................................................................
[bugfix] Timeout session.requests
With 2.1 release requests library was introduced but there is no default
timout. Without any timeout setting, scripts may freeze.
Re-use old config.socket_timeout but take a float value for the new library.
Keep compatible if an int value is given until now.
Bug: T91236
Bug: T102462
Bug: T102113
Change-Id: Iaa7fb4cc8970b6b9ad8b191f2106104fcf7f8884
---
M pywikibot/comms/http.py
M pywikibot/config2.py
2 files changed, 7 insertions(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 6663462..c58524d 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -244,10 +244,10 @@
uri = http_request.uri
body = http_request.body
headers = http_request.headers
-
+ timeout = config.socket_timeout
try:
request = session.request(method, uri, data=body, headers=headers,
- verify=True)
+ verify=True, timeout=timeout)
except Exception as e:
http_request.data = e
else:
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index d70f780..eb28ea1 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -706,8 +706,11 @@
# DISABLED FUNCTION. Setting this variable will not have any effect.
persistent_http = False
-# Default socket timeout. Set to None to disable timeouts.
-socket_timeout = 120 # set a pretty long timeout just in case...
+# Default socket timeout in seconds.
+# DO NOT set to None to disable timeouts. Otherwise this may freeze your
script.
+# You may assign either a tuple of two int or float values for connection and
+# read timeout, or a single value for both.
+socket_timeout = (30, 120)
# ############# COSMETIC CHANGES SETTINGS ##############
--
To view, visit https://gerrit.wikimedia.org/r/218616
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaa7fb4cc8970b6b9ad8b191f2106104fcf7f8884
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits