From c3780710a75c91814b1b101261ada1662e3bbcc1 Mon Sep 17 00:00:00 2001 From: theshteves Date: Sun, 31 Mar 2024 16:25:03 -0400 Subject: [PATCH] Fixed `x86.py -S` printstats compatibility bugs in both Python 2 AND 3 --- threads-intro/x86.py | 11 +++++++---- threads-locks/x86.py | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/threads-intro/x86.py b/threads-intro/x86.py index 1593f9f1..ae81920f 100755 --- a/threads-intro/x86.py +++ b/threads-intro/x86.py @@ -6,19 +6,22 @@ import random from optparse import OptionParser -# to make Python2 and Python3 act the same -- how dumb def random_seed(seed): try: + # Introduced in Python 3.2 to match legacy versions + # https://docs.python.org/3.2/library/random.html#random.seed random.seed(seed, version=1) except: - random.seed(seed) + random.seed(seed) # before Python 3.2 (including Python 2) return def time_clock(): try: - rc = time_clock() - except: + # Introduced in Python 3.3 + # https://docs.python.org/3/library/time.html#time.process_time rc = time.process_time() + except: + rc = time.clock() # before Python 3.3 (including Python 2) return rc # diff --git a/threads-locks/x86.py b/threads-locks/x86.py index 7bcf1f5b..75789c5f 100755 --- a/threads-locks/x86.py +++ b/threads-locks/x86.py @@ -6,19 +6,22 @@ import random from optparse import OptionParser -# to make Python2 and Python3 act the same -- how dumb def random_seed(seed): try: + # Introduced in Python 3.2 to match legacy versions + # https://docs.python.org/3.2/library/random.html#random.seed random.seed(seed, version=1) except: - random.seed(seed) + random.seed(seed) # before Python 3.2 (including Python 2) return def time_clock(): try: - rc = time_clock() - except: + # Introduced in Python 3.3 + # https://docs.python.org/3/library/time.html#time.process_time rc = time.process_time() + except: + rc = time.clock() # before Python 3.3 (including Python 2) return rc #