diff options
| author | Przemysław Suliga <1270737+suligap@users.noreply.github.com> | 2019-05-08 18:34:22 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-05-08 18:34:22 +0200 |
| commit | af5ec222ccd24e81f9fec6c34836a4e503e7ccf7 (patch) | |
| tree | 54ecdd721ed1c66be166bd93f870cca182e0cac3 /django/db/backends/base/base.py | |
| parent | 30dd43884e8e5dfb3dfd7e31fc78fd569f15916a (diff) | |
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/base/base.py')
| -rw-r--r-- | django/db/backends/base/base.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py index 9fa03cc0ee..057fe8ac43 100644 --- a/django/db/backends/base/base.py +++ b/django/db/backends/base/base.py @@ -187,7 +187,7 @@ class BaseDatabaseWrapper: self.needs_rollback = False # Reset parameters defining when to close the connection max_age = self.settings_dict['CONN_MAX_AGE'] - self.close_at = None if max_age is None else time.time() + max_age + self.close_at = None if max_age is None else time.monotonic() + max_age self.closed_in_transaction = False self.errors_occurred = False # Establish the connection @@ -510,7 +510,7 @@ class BaseDatabaseWrapper: self.close() return - if self.close_at is not None and time.time() >= self.close_at: + if self.close_at is not None and time.monotonic() >= self.close_at: self.close() return |
