# HG changeset patch # User Martin Bornhold # Date 2016-06-22 08:18:06 # Node ID dae685be89fb0043c2bac6eb73d92daf690df612 # Parent 96f10eea3b38135b950412bcfb999bb5ed6041d4 threading: Add factory that creates curl session for each thread. When creating a repo with an import url pointing to another repo on the same enterprise instance we call the vcssserver to check the url. The vcsserver then calls to enterprise to verify the url. This leads to two threads using the same cur session. diff --git a/rhodecode/lib/vcs/client_http.py b/rhodecode/lib/vcs/client_http.py --- a/rhodecode/lib/vcs/client_http.py +++ b/rhodecode/lib/vcs/client_http.py @@ -31,6 +31,7 @@ implementation. import copy import logging +import threading import urllib2 import urlparse import uuid @@ -38,7 +39,7 @@ import uuid import msgpack import requests -from . import exceptions +from . import exceptions, CurlSession log = logging.getLogger(__name__) @@ -216,3 +217,17 @@ class VcsHttpProxy(object): headers = iterator.next() return iterator, status, headers + + +class ThreadlocalSessionFactory(object): + """ + Creates one CurlSession per thread on demand. + """ + + def __init__(self): + self._thread_local = threading.local() + + def __call__(self): + if not hasattr(self._thread_local, 'curl_session'): + self._thread_local.curl_session = CurlSession() + return self._thread_local.curl_session