Use a per-thread requests.Session instead of module-level sessions - #981
Merged
Merged
Conversation
Replace the shared module-level helpers_session/default_session with a lazily created session per thread (requests.Session isn't thread-safe). Connections are still kept alive between calls within a thread. wbi_helpers.default_session and helpers_session remain available through a module __getattr__ that emits a DeprecationWarning. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
LeMyst
force-pushed
the
improve-sessions
branch
from
September 19, 2026 14:55
bb95e4f to
b3adada
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the shared module-level
requests.Sessionobjects (helpers_session,default_session) inwbi_helperswith a session created lazily per thread.requests.Sessionisn't thread-safe: sharing one global session across threads (multi-threaded bots) could mix connections, cookies and headers.mediawiki_api_call(when no session/login is given),execute_sparql_queryanddownload_entity_ttl.wbi_helpers.default_sessionandwbi_helpers.helpers_sessionare still accessible via a module__getattr__, returning the current thread's session with aDeprecationWarning.Rebased on master (was conflicting with #983 / #999).
🤖 Generated with Claude Code