From 48e20ce79603b0dd3e4c2d226dacac6f15ad4f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Ren=C3=A9?= Date: Wed, 17 Jun 2020 14:29:29 +0200 Subject: [PATCH] Replace deprecated time.clock() with time.process_time() time.clock() is deprecated since Python 3.3 and no longer available on Python 3.8. See https://docs.python.org/3/whatsnew/3.8.html#api-and-feature-removals Includes an import guard to maintain Python 2.7 support. --- sumatra/tee.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sumatra/tee.py b/sumatra/tee.py index a2123083..4453f590 100644 --- a/sumatra/tee.py +++ b/sumatra/tee.py @@ -5,7 +5,11 @@ from __future__ import print_function from __future__ import unicode_literals from builtins import str -import logging, sys, signal, subprocess, types, time, os, codecs, platform +import logging, sys, signal, subprocess, types, os, codecs, platform +try: + from time import process_time +except ImportError: # Python 2.7 fallback + from time import clock as process_time string_types = str, @@ -70,7 +74,7 @@ def system2(cmd, cwd=None, logger=_sentinel, stdout=_sentinel, log_command=_sent This method return (returncode, output_lines_as_list) """ - t = time.clock() + t = process_time() output = [] if log_command is _sentinel: log_command = globals().get('log_command') if timing is _sentinel: timing = globals().get('timing') @@ -155,7 +159,7 @@ def nop(msg): sys.stdout.flush() returncode = p.wait() except KeyboardInterrupt: - # Popen.returncode: + # Popen.returncode: # "A negative value -N indicates that the child was terminated by signal N (Unix only)." # see https://docs.python.org/2/library/subprocess.html#subprocess.Popen.returncode returncode = -signal.SIGINT @@ -164,7 +168,7 @@ def nop(msg): def secondsToStr(t): from functools import reduce return "%02d:%02d:%02d" % reduce(lambda ll,b : divmod(ll[0],b) + ll[1:], [(t*1000,),1000,60,60])[:3] - mylogger("Returned: %d (execution time %s)\n" % (returncode, secondsToStr(time.clock()-t))) + mylogger("Returned: %d (execution time %s)\n" % (returncode, secondsToStr(process_time()-t))) else: mylogger("Returned: %d\n" % (returncode))