diff --git a/src/class_objectProcessorQueue.py b/src/class_objectProcessorQueue.py index b6628816..ec00238a 100644 --- a/src/class_objectProcessorQueue.py +++ b/src/class_objectProcessorQueue.py @@ -1,12 +1,12 @@ -import Queue +from queue import Queue import threading import time -class ObjectProcessorQueue(Queue.Queue): +class ObjectProcessorQueue(Queue): maxSize = 32000000 def __init__(self): - Queue.Queue.__init__(self) + Queue.__init__(self) self.sizeLock = threading.Lock() self.curSize = 0 # in Bytes. We maintain this to prevent nodes from flooing us with objects which take up too much memory. If this gets too big we'll sleep before asking for further objects. @@ -15,10 +15,10 @@ class ObjectProcessorQueue(Queue.Queue): time.sleep(1) with self.sizeLock: self.curSize += len(item[1]) - Queue.Queue.put(self, item, block, timeout) + Queue.put(self, item, block, timeout) def get(self, block = True, timeout = None): - item = Queue.Queue.get(self, block, timeout) + item = Queue.get(self, block, timeout) with self.sizeLock: self.curSize -= len(item[1]) return item diff --git a/src/helper_bitcoin.py b/src/helper_bitcoin.py index d56e395b..cf24b8b9 100644 --- a/src/helper_bitcoin.py +++ b/src/helper_bitcoin.py @@ -4,7 +4,7 @@ from pyelliptic import arithmetic # This function expects that pubkey begin with \x04 def calculateBitcoinAddressFromPubkey(pubkey): if len(pubkey) != 65: - print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.' + print('Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.') return "error" ripe = hashlib.new('ripemd160') sha = hashlib.new('sha256') @@ -25,7 +25,7 @@ def calculateBitcoinAddressFromPubkey(pubkey): def calculateTestnetAddressFromPubkey(pubkey): if len(pubkey) != 65: - print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.' + print('Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.') return "error" ripe = hashlib.new('ripemd160') sha = hashlib.new('sha256') diff --git a/src/helper_threading.py b/src/helper_threading.py index 6b6a5e25..b4d0f03d 100644 --- a/src/helper_threading.py +++ b/src/helper_threading.py @@ -3,23 +3,10 @@ from contextlib import contextmanager import threading -try: - import prctl -except ImportError: - def set_thread_name(name): - """Set the thread name for external use (visible from the OS).""" - threading.current_thread().name = name -else: - def set_thread_name(name): - """Set a name for the thread for python internal use.""" - prctl.set_name(name) - def _thread_name_hack(self): - set_thread_name(self.name) - threading.Thread.__bootstrap_original__(self) - - threading.Thread.__bootstrap_original__ = threading.Thread._Thread__bootstrap - threading.Thread._Thread__bootstrap = _thread_name_hack +def set_thread_name(name): + """Set the thread name for external use (visible from the OS).""" + threading.current_thread().name = name class StoppableThread(object): diff --git a/src/messagetypes/__init__.py b/src/messagetypes/__init__.py index e643bbc2..b9efe6a6 100644 --- a/src/messagetypes/__init__.py +++ b/src/messagetypes/__init__.py @@ -8,7 +8,6 @@ from builtins import * from builtins import object from importlib import import_module from os import path, listdir -from string import lower from debug import logger import messagetypes @@ -16,7 +15,7 @@ import paths class MsgBase(object): def encode(self): - self.data = {"": lower(type(self).__name__)} + self.data = {"": type(self).__name__.lower()} def constructObject(data): diff --git a/src/multiqueue.py b/src/multiqueue.py index 8c64d33d..1d4122e0 100644 --- a/src/multiqueue.py +++ b/src/multiqueue.py @@ -3,13 +3,13 @@ src/multiqueue.py ================= """ -import Queue +from queue import Queue from collections import deque import helper_random -class MultiQueue(Queue.Queue): +class MultiQueue(Queue): """A base queue class""" # pylint: disable=redefined-builtin,attribute-defined-outside-init defaultQueueCount = 10 @@ -19,7 +19,7 @@ class MultiQueue(Queue.Queue): self.queueCount = MultiQueue.defaultQueueCount else: self.queueCount = count - Queue.Queue.__init__(self, maxsize) + Queue.__init__(self, maxsize) # Initialize the queue representation def _init(self, maxsize): diff --git a/src/openclpow.py b/src/openclpow.py index eb91a07f..75cabd97 100644 --- a/src/openclpow.py +++ b/src/openclpow.py @@ -107,9 +107,9 @@ def do_opencl_pow(hash, target): #initCL() if __name__ == "__main__": - target = 54227212183L + target = 54227212183 initialHash = "3758f55b5a8d902fd3597e4ce6a2d3f23daff735f65d9698c270987f4e67ad590b93f3ffeba0ef2fd08a8dc2f87b68ae5a0dc819ab57f22ad2c4c9c8618a43b3".decode("hex") nonce = do_opencl_pow(initialHash.encode("hex"), target) trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8]) - print "{} - value {} < {}".format(nonce, trialValue, target) + print("{} - value {} < {}".format(nonce, trialValue, target)) diff --git a/src/queues.py b/src/queues.py index 7b6bbade..f852ac46 100644 --- a/src/queues.py +++ b/src/queues.py @@ -1,20 +1,20 @@ -import Queue +from queue import Queue from class_objectProcessorQueue import ObjectProcessorQueue from multiqueue import MultiQueue -workerQueue = Queue.Queue() -UISignalQueue = Queue.Queue() -addressGeneratorQueue = Queue.Queue() +workerQueue = Queue() +UISignalQueue = Queue() +addressGeneratorQueue = Queue() # receiveDataThreads dump objects they hear on the network into this # queue to be processed. objectProcessorQueue = ObjectProcessorQueue() invQueue = MultiQueue() addrQueue = MultiQueue() -portCheckerQueue = Queue.Queue() -receiveDataQueue = Queue.Queue() +portCheckerQueue = Queue() +receiveDataQueue = Queue() # The address generator thread uses this queue to get information back # to the API thread. -apiAddressGeneratorReturnQueue = Queue.Queue() +apiAddressGeneratorReturnQueue = Queue() # Exceptions -excQueue = Queue.Queue() +excQueue = Queue() diff --git a/src/randomtrackingdict.py b/src/randomtrackingdict.py index 6c3300ab..7b9be67a 100644 --- a/src/randomtrackingdict.py +++ b/src/randomtrackingdict.py @@ -140,20 +140,20 @@ if __name__ == '__main__': k = RandomTrackingDict() d = {} - print "populating random tracking dict" + print("populating random tracking dict") a.append(time()) for i in range(50000): k[randString()] = True a.append(time()) - print "done" + print("done") while k: retval = k.randomKeys(1000) if not retval: - print "error getting random keys" + print("error getting random keys") try: k.randomKeys(100) - print "bad" + print("bad") except KeyError: pass for i in retval: @@ -161,4 +161,4 @@ if __name__ == '__main__': a.append(time()) for x in range(len(a) - 1): - print "%i: %.3f" % (x, a[x + 1] - a[x]) + print("%i: %.3f" % (x, a[x + 1] - a[x])) diff --git a/src/tr.py b/src/tr.py index 8b41167f..3337e4c2 100644 --- a/src/tr.py +++ b/src/tr.py @@ -25,8 +25,8 @@ def translateText(context, text, n = None): try: from PyQt4 import QtCore, QtGui except Exception as err: - print 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon' - print 'Error message:', err + print('PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon') + print('Error message:', err) os._exit(0) if n is None: return QtGui.QApplication.translate(context, text)