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). --- django/core/management/commands/migrate.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'django/core') diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index 7eaad620b5..37914e2622 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -261,33 +261,33 @@ class Command(BaseCommand): compute_time = self.verbosity > 1 if action == "apply_start": if compute_time: - self.start = time.time() + self.start = time.monotonic() self.stdout.write(" Applying %s..." % migration, ending="") self.stdout.flush() elif action == "apply_success": - elapsed = " (%.3fs)" % (time.time() - self.start) if compute_time else "" + elapsed = " (%.3fs)" % (time.monotonic() - self.start) if compute_time else "" if fake: self.stdout.write(self.style.SUCCESS(" FAKED" + elapsed)) else: self.stdout.write(self.style.SUCCESS(" OK" + elapsed)) elif action == "unapply_start": if compute_time: - self.start = time.time() + self.start = time.monotonic() self.stdout.write(" Unapplying %s..." % migration, ending="") self.stdout.flush() elif action == "unapply_success": - elapsed = " (%.3fs)" % (time.time() - self.start) if compute_time else "" + elapsed = " (%.3fs)" % (time.monotonic() - self.start) if compute_time else "" if fake: self.stdout.write(self.style.SUCCESS(" FAKED" + elapsed)) else: self.stdout.write(self.style.SUCCESS(" OK" + elapsed)) elif action == "render_start": if compute_time: - self.start = time.time() + self.start = time.monotonic() self.stdout.write(" Rendering model states...", ending="") self.stdout.flush() elif action == "render_success": - elapsed = " (%.3fs)" % (time.time() - self.start) if compute_time else "" + elapsed = " (%.3fs)" % (time.monotonic() - self.start) if compute_time else "" self.stdout.write(self.style.SUCCESS(" DONE" + elapsed)) def sync_apps(self, connection, app_labels): -- cgit v1.3