Use time.process_time() instead of deprecated clock()
authorDenis Laxalde <denis.laxalde@logilab.fr>
Tue, 09 Jul 2019 14:35:44 +0200
changeset 12681 42afaaf708d8
parent 12680 30a98fd4ce31
child 12682 da36da3f89f1
Use time.process_time() instead of deprecated clock() This fixes: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
cubicweb/web/application.py
--- a/cubicweb/web/application.py	Tue Jul 09 14:20:30 2019 +0200
+++ b/cubicweb/web/application.py	Tue Jul 09 14:35:44 2019 +0200
@@ -22,7 +22,7 @@
 import http.client as http_client
 import json
 import sys
-from time import clock, time
+from time import process_time, time
 from contextlib import contextmanager
 
 from rql import BadRQLQuery
@@ -205,9 +205,10 @@
                 orig_execute = cnx.execute
 
                 def execute(rql, kwargs=None, build_descr=True):
-                    tstart, cstart = time(), clock()
+                    tstart, cstart = time(), process_time()
                     rset = orig_execute(rql, kwargs, build_descr=build_descr)
-                    cnx.executed_queries.append((rql, kwargs, time() - tstart, clock() - cstart))
+                    cnx.executed_queries.append((rql, kwargs, time() - tstart,
+                                                 process_time() - cstart))
                     return rset
 
                 return execute
@@ -220,14 +221,14 @@
             return set_cnx
 
         req.set_cnx = wrap_set_cnx(req.set_cnx)
-        tstart, cstart = time(), clock()
+        tstart, cstart = time(), process_time()
         try:
             return self.main_handle_request(req)
         finally:
             cnx = req.cnx
             if cnx and cnx.executed_queries:
                 with self._logfile_lock:
-                    tend, cend = time(), clock()
+                    tend, cend = time(), process_time()
                     try:
                         result = ['\n' + '*' * 80]
                         result.append('%s -- (%.3f sec, %.3f CPU sec)' % (
@@ -335,7 +336,7 @@
                    req.session.sessionid, list(req.form))
         # remove user callbacks on a new request (except for json controllers
         # to avoid callbacks being unregistered before they could be called)
-        tstart = clock()
+        tstart = process_time()
         commited = False
         try:
             # standard processing of the request
@@ -404,7 +405,7 @@
                 except Exception:
                     pass  # ignore rollback error at this point
         self.add_undo_link_to_msg(req)
-        self.debug('query %s executed in %s sec', path, clock() - tstart)
+        self.debug('query %s executed in %s sec', path, process_time() - tstart)
         return result
 
     # Error handlers