From af5ec222ccd24e81f9fec6c34836a4e503e7ccf7 Mon Sep 17 00:00:00 2001 From: Przemysław Suliga <1270737+suligap@users.noreply.github.com> Date: Wed, 8 May 2019 18:34:22 +0200 Subject: Used time.monotonic() instead of time.time() where applicable. time.monotonic() available from Python 3.3: - Nicely communicates a narrow intent of "get a local system monotonic clock time" instead of possible "get a not necessarily accurate Unix time stamp because it needs to be communicated to outside of this process/machine" when time.time() is used. - Its result isn't affected by the system clock updates. There are two classes of time.time() uses changed to time.monotonic() by this change: - measuring time taken to run some code. - setting and checking a "close_at" threshold for for persistent db connections (django/db/backends/base/base.py). --- docs/topics/db/instrumentation.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/topics/db/instrumentation.txt b/docs/topics/db/instrumentation.txt index 529347094f..933c67a96d 100644 --- a/docs/topics/db/instrumentation.txt +++ b/docs/topics/db/instrumentation.txt @@ -69,7 +69,7 @@ For a more complete example, a query logger could look like this:: def __call__(self, execute, sql, params, many, context): current_query = {'sql': sql, 'params': params, 'many': many} - start = time.time() + start = time.monotonic() try: result = execute(sql, params, many, context) except Exception as e: @@ -80,7 +80,7 @@ For a more complete example, a query logger could look like this:: current_query['status'] = 'ok' return result finally: - duration = time.time() - start + duration = time.monotonic() - start current_query['duration'] = duration self.queries.append(current_query) -- cgit v1.3