Skip to content

Commit

Permalink
Merge pull request #389 from alcrene/fix-time-clock
Browse files Browse the repository at this point in the history
Replace deprecated time.clock() with time.process_time()
  • Loading branch information
apdavison authored Oct 21, 2020
2 parents 3df9bca + 48e20ce commit 2ff2a35
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 2ff2a35

Please sign in to comment.