Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed x86.py -S printstats compatibility bugs in both Python 2 AND 3 #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions threads-intro/x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
11 changes: 7 additions & 4 deletions threads-locks/x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down