[PATCH logilab-common] Use time.process_time instead of time.clock (deprecated)

Simon Chabot simon.chabot at logilab.fr
Thu Oct 24 15:08:06 CEST 2019


# HG changeset patch
# User Simon Chabot <simon.chabot at logilab.fr>
# Date 1571921749 -7200
#      Thu Oct 24 14:55:49 2019 +0200
# Node ID 6e9fe3fab93b3cc02bfff5287cd4d15248c85c06
# Parent  5bfba850fddf7f63508c74e40afa8ec9d0ba468b
# Available At https://hg.logilab.org/review/logilab/common
#              hg pull https://hg.logilab.org/review/logilab/common -r 6e9fe3fab93b
Use time.process_time instead of time.clock (deprecated)

time.clock is deprecated since python 3.3 and will be removed in python 3.8
time.clock is used if process_time is not available (python2 for instance)

diff -r 5bfba850fddf -r 6e9fe3fab93b logilab/common/decorators.py
--- a/logilab/common/decorators.py	Thu Sep 12 16:25:16 2019 +0200
+++ b/logilab/common/decorators.py	Thu Oct 24 14:55:49 2019 +0200
@@ -23,7 +23,11 @@
 
 import sys
 import types
-from time import clock, time
+from time import time
+try:
+    from time import process_time
+except ImportError:
+    from time import clock as process_time
 from inspect import isgeneratorfunction
 
 import six
@@ -232,10 +236,10 @@
 def timed(f):
     def wrap(*args, **kwargs):
         t = time()
-        c = clock()
+        c = process_time()
         res = f(*args, **kwargs)
         print('%s clock: %.9f / time: %.9f' % (f.__name__,
-                                               clock() - c, time() - t))
+                                               process_time() - c, time() - t))
         return res
     return wrap
 
diff -r 5bfba850fddf -r 6e9fe3fab93b logilab/common/pytest.py
--- a/logilab/common/pytest.py	Thu Sep 12 16:25:16 2019 +0200
+++ b/logilab/common/pytest.py	Thu Oct 24 14:55:49 2019 +0200
@@ -115,7 +115,11 @@
 
 import os, sys, re
 import os.path as osp
-from time import time, clock
+from time import time
+try:
+    from time import process_time
+except ImportError:
+    from time import clock as process_time
 import warnings
 import types
 import inspect
@@ -385,7 +389,7 @@
         print(('  %s  ' % osp.basename(filename)).center(70, '='),
               file=sys.__stderr__)
         try:
-            tstart, cstart = time(), clock()
+            tstart, cstart = time(), process_time()
             try:
                 testprog = SkipAwareTestProgram(modname, batchmode=batchmode, cvg=self.cvg,
                                                  options=self.options, outstream=sys.stderr)
@@ -406,7 +410,7 @@
                 traceback.print_exc(file=sys.stderr)
                 return None
 
-            tend, cend = time(), clock()
+            tend, cend = time(), process_time()
             ttime, ctime = (tend - tstart), (cend - cstart)
             self.report.feed(filename, testprog.result, ttime, ctime)
             return testprog
@@ -515,10 +519,10 @@
               file=sys.stderr)
         try:
             try:
-                tstart, cstart = time(), clock()
+                tstart, cstart = time(), process_time()
                 self.before_testfile()
                 testprog = SkipAwareTestProgram(modname, batchmode=batchmode, cvg=self.cvg)
-                tend, cend = time(), clock()
+                tend, cend = time(), process_time()
                 ttime, ctime = (tend - tstart), (cend - cstart)
                 self.report.feed(filename, testprog.result, ttime, ctime)
                 return testprog



More information about the cubicweb-devel mailing list