Skip to content

Commit 76895a0

Browse files
authored
Cache truststore SSLContext as load_verify_locations() is slow (#13199)
SSLContext can be reused across connections as per the Python docs: > SSLContext is designed to be shared and used by multiple connections. > Thus, it is thread-safe as long as it is not reconfigured after being > used by a connection. In addition, requests has been using a global SSLContext and the world hasn't blown up so I'm going to say this is pretty safe.
1 parent af92b41 commit 76895a0

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/pip/_internal/cli/index_command.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
import os
1111
import sys
12+
from functools import lru_cache
1213
from optparse import Values
1314
from typing import TYPE_CHECKING, List, Optional
1415

@@ -25,6 +26,7 @@
2526
logger = logging.getLogger(__name__)
2627

2728

29+
@lru_cache
2830
def _create_truststore_ssl_context() -> Optional["SSLContext"]:
2931
if sys.version_info < (3, 10):
3032
logger.debug("Disabling truststore because Python version isn't 3.10+")

0 commit comments

Comments
 (0)