Skip to content

Commit

Permalink
RF/OPT: delay import of requests until used/needed in _etrequest
Browse files Browse the repository at this point in the history
It is a partial workaround for
sensein#29
where ultimately requests is not a dependency at all, but rather built-in http
is used for that minimal amount of interaction needed.

This minimal change should shave off about 60ms from etelemetry import/use
runtime whenever no refresh _etrequest is needed to be sent
  • Loading branch information
yarikoptic committed Jan 5, 2021
1 parent ca72400 commit 82893a6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion etelemetry/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from requests import request, ConnectionError, ReadTimeout
import os

try:
Expand All @@ -21,6 +20,9 @@ class BadVersionError(RuntimeError):


def _etrequest(endpoint, method="get", **kwargs):
# Delay requests import until actually used to at least not
# add runtime penalty of requests import whenever not needed
from requests import request, ConnectionError, ReadTimeout
if kwargs.get('timeout') is None:
kwargs['timeout'] = 5

Expand Down

0 comments on commit 82893a6

Please sign in to comment.