summaryrefslogtreecommitdiff
path: root/django/db/backends/utils.py
diff options
context:
space:
mode:
authorPrzemysław Suliga <1270737+suligap@users.noreply.github.com>2019-05-08 18:34:22 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-05-08 18:34:22 +0200
commitaf5ec222ccd24e81f9fec6c34836a4e503e7ccf7 (patch)
tree54ecdd721ed1c66be166bd93f870cca182e0cac3 /django/db/backends/utils.py
parent30dd43884e8e5dfb3dfd7e31fc78fd569f15916a (diff)
downloaddjango-af5ec222ccd24e81f9fec6c34836a4e503e7ccf7.tar.gz
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).
Diffstat (limited to 'django/db/backends/utils.py')
-rw-r--r--django/db/backends/utils.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py
index e52d39c69b..2416a458ba 100644
--- a/django/db/backends/utils.py
+++ b/django/db/backends/utils.py
@@ -3,8 +3,8 @@ import decimal
import functools
import hashlib
import logging
+import time
from contextlib import contextmanager
-from time import time
from django.conf import settings
from django.db.utils import NotSupportedError
@@ -105,11 +105,11 @@ class CursorDebugWrapper(CursorWrapper):
@contextmanager
def debug_sql(self, sql=None, params=None, use_last_executed_query=False, many=False):
- start = time()
+ start = time.monotonic()
try:
yield
finally:
- stop = time()
+ stop = time.monotonic()
duration = stop - start
if use_last_executed_query:
sql = self.db.ops.last_executed_query(self.cursor, sql, params)