Added generic multiprocess wrapper

Corrected blocks after timeout function
This commit is contained in:
Kevin F 2022-02-04 00:18:57 -06:00
parent eb763cf293
commit 061e2d1e01
2 changed files with 29 additions and 3 deletions

View File

@ -18,10 +18,14 @@ def get_blocks_by_type(block_type):
if block.type == block_type: if block.type == block_type:
yield block yield block
def get_blocks_after_timestamp(timestamp: int, block_type: bytes = ''): def get_blocks_after_timestamp(timestamp: int, block_type: bytes = ''):
block_db = db.get_db_obj(block_db_path, 'u') block_db = db.get_db_obj(block_db_path, 'u')
for block_hash in db.list_keys(block_db_path): for block_hash in db.list_keys(block_db_path):
block = Block(block_hash, block_db[block_hash], auto_verify=False) block = Block(block_hash, block_db[block_hash], auto_verify=False)
if block.type == block_type: if block.timestamp > timestamp:
yield block if block_type:
if block_type == block.type:
yield block
else:
yield block

View File

@ -0,0 +1,22 @@
from audioop import mul
import multiprocessing
def run_func_in_new_process(func, *args, **kwargs):
queue = multiprocessing.Queue()
def _wrap_func():
if args and kwargs:
queue.put(func(*args, **kwargs))
elif args:
queue.put(func(*args))
elif kwargs:
queue.put(func(**kwargs))
else:
queue.put(func())
proc = multiprocessing.Process(target=_wrap_func, daemon=True)
proc.start()
return queue.get()