Implement permanently running worker thread

This commit is contained in:
Lee Miller 2023-10-16 13:59:36 +03:00
parent ff63139d78
commit 2e19e12933
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 20 additions and 5 deletions

View File

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

View File

@ -64,3 +64,5 @@ connection_limit = 250
objects = {}
objects_lock = threading.Lock()
objects_queue = queue.Queue()