Implement permanently running worker thread
This commit is contained in:
parent
ff63139d78
commit
2e19e12933
|
@ -11,7 +11,7 @@ import struct
|
|||
import threading
|
||||
import time
|
||||
|
||||
from . import shared, structure
|
||||
from . import message, shared, structure
|
||||
|
||||
|
||||
def _pow_worker(target, initial_hash, q):
|
||||
|
@ -100,13 +100,26 @@ class Worker(threading.Thread):
|
|||
|
||||
return obj
|
||||
|
||||
@staticmethod
|
||||
def _publish(obj):
|
||||
with shared.objects_lock:
|
||||
shared.objects[obj.vector] = obj
|
||||
shared.vector_advertise_queue.put(obj.vector)
|
||||
|
||||
def run(self):
|
||||
if self.obj:
|
||||
obj = self.add_pow(self.obj)
|
||||
self._publish(self.add_pow(self.obj))
|
||||
return
|
||||
|
||||
with shared.objects_lock:
|
||||
shared.objects[obj.vector] = obj
|
||||
shared.vector_advertise_queue.put(obj.vector)
|
||||
while not shared.shutting_down:
|
||||
data = shared.objects_queue.get()
|
||||
|
||||
obj = structure.Object.from_message(
|
||||
message.Message.from_bytes(data))
|
||||
if int.from_bytes(obj.nonce, 'big') == 0:
|
||||
obj = self.add_pow(obj)
|
||||
|
||||
self._publish(obj)
|
||||
|
||||
|
||||
def do_pow_and_publish(obj):
|
||||
|
|
|
@ -64,3 +64,5 @@ connection_limit = 250
|
|||
|
||||
objects = {}
|
||||
objects_lock = threading.Lock()
|
||||
|
||||
objects_queue = queue.Queue()
|
||||
|
|
Loading…
Reference in New Issue