Skip to content

Commit a1cfd6e

Browse files
Neeratyoymfeurer
authored andcommitted
Adding option to print logs during an api call (#833)
* Adding option to print logs during an api call * Adding timing to log and changing string interpolation * Improving logging and timing of api calls * PEP8 * PEP8
1 parent c02096b commit a1cfd6e

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

openml/_api_calls.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# License: BSD 3-Clause
22

33
import time
4-
from typing import Dict
4+
import logging
55
import requests
66
import warnings
7-
87
import xmltodict
8+
from typing import Dict
99

1010
from . import config
1111
from .exceptions import (OpenMLServerError, OpenMLServerException,
@@ -45,13 +45,22 @@ def _perform_api_call(call, request_method, data=None, file_elements=None):
4545
url += call
4646

4747
url = url.replace('=', '%3d')
48-
48+
logging.info('Starting [%s] request for the URL %s', request_method, url)
49+
start = time.time()
4950
if file_elements is not None:
5051
if request_method != 'post':
5152
raise ValueError('request method must be post when file elements '
5253
'are present')
53-
return _read_url_files(url, data=data, file_elements=file_elements)
54-
return _read_url(url, request_method, data)
54+
response = _read_url_files(url, data=data, file_elements=file_elements)
55+
else:
56+
response = _read_url(url, request_method, data)
57+
logging.info(
58+
'%.7fs taken for [%s] request for the URL %s',
59+
time.time() - start,
60+
request_method,
61+
url,
62+
)
63+
return response
5564

5665

5766
def _file_id_to_url(file_id, filename=None):

0 commit comments

Comments
 (0)