checking in python3 progress...

This commit is contained in:
Chapman Shoop 2019-08-17 21:24:26 -07:00
parent 83ccc9e39a
commit 7074a5d3df
9 changed files with 31 additions and 45 deletions

View File

@ -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

View File

@ -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')

View File

@ -3,23 +3,10 @@
from contextlib import contextmanager
import threading
try:
import prctl
except ImportError:
def set_thread_name(name):
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
class StoppableThread(object):

View File

@ -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):

View File

@ -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):

View File

@ -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))

View File

@ -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()

View File

@ -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]))

View File

@ -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)