Skip to content

Commit

Permalink
Replace deprecated time.clock() with time.process_time()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alcrene committed Jun 17, 2020
1 parent 99503e2 commit 48e20ce
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sumatra/tee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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))

Expand Down

0 comments on commit 48e20ce

Please sign in to comment.