Skip to content

Commit

Permalink
Use a thread local for sessions instead
Browse files Browse the repository at this point in the history
  • Loading branch information
danpalmer committed Apr 19, 2018
1 parent 968f6dc commit ba95b30
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions routemaster/feeds.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Creation and fetching of feed data."""
import functools
import threading
from typing import Any, Dict, Callable, Optional

import requests
Expand All @@ -21,9 +21,13 @@ class FeedNotFetched(Exception):
pass


@functools.lru_cache()
_feed_sessions = threading.local()


def _get_feed_session():
return requests.Session()
if not hasattr(_feed_sessions, 'session'):
_feed_sessions.session = requests.Session()
return _feed_sessions.session


@dataclass
Expand Down

0 comments on commit ba95b30

Please sign in to comment.