From 3b31e03a2124bfab6c7524b676ccf5c2081f62b9 Mon Sep 17 00:00:00 2001 From: DemidovVladimir Date: Wed, 16 Jun 2021 17:58:25 +0200 Subject: [PATCH 1/2] replace clock method it is removed from package --- BitTornado/Application/PeerID.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BitTornado/Application/PeerID.py b/BitTornado/Application/PeerID.py index c47dbdf..80c3511 100644 --- a/BitTornado/Application/PeerID.py +++ b/BitTornado/Application/PeerID.py @@ -31,8 +31,8 @@ def reset(self): except IOError: x = b'' - tic = time.clock() - toc1 = countwhile(lambda x: tic == time.clock()) + tic = time.process_time() + toc1 = countwhile(lambda x: tic == time.process_time()) tic = int(time.time() * 100) toc2 = countwhile(lambda x: tic == int(time.time() * 100)) tic = int(time.time() * 10) From 9dd3a145f1035c3172a54938121ca70fe577f3ca Mon Sep 17 00:00:00 2001 From: DemidovVladimir Date: Wed, 16 Jun 2021 18:25:06 +0200 Subject: [PATCH 2/2] use time clock or perf_counter compatibility --- BitTornado/Application/PeerID.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/BitTornado/Application/PeerID.py b/BitTornado/Application/PeerID.py index 80c3511..20282ab 100644 --- a/BitTornado/Application/PeerID.py +++ b/BitTornado/Application/PeerID.py @@ -1,10 +1,15 @@ import os -import time import base64 import hashlib import itertools import BitTornado +"""Use time clock or perf_counter, depending on python version""" +try: + from time import perf_counter, time +except ImportError: + from time import clock, time as perf_counter, time + mapbase64 = b'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-' @@ -31,15 +36,15 @@ def reset(self): except IOError: x = b'' - tic = time.process_time() - toc1 = countwhile(lambda x: tic == time.process_time()) - tic = int(time.time() * 100) - toc2 = countwhile(lambda x: tic == int(time.time() * 100)) - tic = int(time.time() * 10) + tic = perf_counter() + toc1 = countwhile(lambda x: tic == perf_counter()) + tic = int(time() * 100) + toc2 = countwhile(lambda x: tic == int(time() * 100)) + tic = int(time() * 10) toc3 = 0 if toc2 >= 1000 else \ - countwhile(lambda x: tic == int(time.time() * 10)) + countwhile(lambda x: tic == int(time() * 10)) - x += '{!r}/{}/{}/{}/{}/{}'.format(time.time(), time.time(), toc1, toc2, + x += '{!r}/{}/{}/{}/{}/{}'.format(time(), time(), toc1, toc2, toc3, os.getpid()).encode() self.randstr = base64.urlsafe_b64encode(