From 98b21d6b8a6d3fd0f1d1803871a871f6d44eaaa9 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Fri, 12 Jul 2024 13:21:49 -0400 Subject: [PATCH] 21935: Merge arvados.timer into arvados._internal It's one small class. It doesn't need a dedicated module. Arvados-DCO-1.1-Signed-off-by: Brett Smith --- sdk/python/arvados/_internal/__init__.py | 17 +++++++++++++++++ sdk/python/arvados/keep.py | 9 +++++---- sdk/python/arvados/timer.py | 20 -------------------- 3 files changed, 22 insertions(+), 24 deletions(-) delete mode 100644 sdk/python/arvados/timer.py diff --git a/sdk/python/arvados/_internal/__init__.py b/sdk/python/arvados/_internal/__init__.py index 66c82870f1..cdc3608026 100644 --- a/sdk/python/arvados/_internal/__init__.py +++ b/sdk/python/arvados/_internal/__init__.py @@ -11,8 +11,25 @@ time. import functools import re +import time import warnings +class Timer: + def __init__(self, verbose=False): + self.verbose = verbose + + def __enter__(self): + self.start = time.time() + return self + + def __exit__(self, *args): + self.end = time.time() + self.secs = self.end - self.start + self.msecs = self.secs * 1000 # millisecs + if self.verbose: + print('elapsed time: %f ms' % self.msecs) + + def deprecated(version=None, preferred=None): """Mark a callable as deprecated in the SDK diff --git a/sdk/python/arvados/keep.py b/sdk/python/arvados/keep.py index 838a9d38c0..2ec23885ad 100644 --- a/sdk/python/arvados/keep.py +++ b/sdk/python/arvados/keep.py @@ -27,12 +27,13 @@ from io import BytesIO import arvados import arvados.config as config +import arvados.diskcache import arvados.errors import arvados.retry as retry import arvados.util -import arvados.diskcache + +from arvados._internal import Timer from arvados._pycurlhelper import PyCurlHelper -from . import timer _logger = logging.getLogger('arvados.keep') global_client_object = None @@ -418,7 +419,7 @@ class KeepClient(object): curl = self._get_user_agent() ok = None try: - with timer.Timer() as t: + with Timer() as t: self._headers = {} response_body = BytesIO() curl.setopt(pycurl.NOSIGNAL, 1) @@ -513,7 +514,7 @@ class KeepClient(object): curl = self._get_user_agent() ok = None try: - with timer.Timer() as t: + with Timer() as t: self._headers = {} body_reader = BytesIO(body) response_body = BytesIO() diff --git a/sdk/python/arvados/timer.py b/sdk/python/arvados/timer.py deleted file mode 100644 index 39dbc7874e..0000000000 --- a/sdk/python/arvados/timer.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) The Arvados Authors. All rights reserved. -# -# SPDX-License-Identifier: Apache-2.0 - -import time - -class Timer(object): - def __init__(self, verbose=False): - self.verbose = verbose - - def __enter__(self): - self.start = time.time() - return self - - def __exit__(self, *args): - self.end = time.time() - self.secs = self.end - self.start - self.msecs = self.secs * 1000 # millisecs - if self.verbose: - print('elapsed time: %f ms' % self.msecs) -- 2.30.2