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