moved ProcessGroup object to tests as it is only used there

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-02-27 13:20:10 +01:00
parent 6d166747d1
commit 6aa37cf6a6
No known key found for this signature in database
3 changed files with 27 additions and 26 deletions

View File

@ -10,31 +10,6 @@ import multiprocessing
import setproctitle
class ProcessGroup(object):
def __init__(self, concurrency=None, group=None, target=None, name=None, args=None, kwargs=None, daemon=None):
self.concurrency = concurrency or multiprocessing.cpu_count()
self.group = group
self.target = target
self.name = name
self.args = args or ()
self.kwargs = kwargs or {}
self.daemon = daemon
self.processes = []
def start(self):
for i in range(self.concurrency):
proc = multiprocessing.Process(
group=self.group,
target=self.target,
name=self.name,
args=self.args,
kwargs=self.kwargs,
daemon=self.daemon,
)
proc.start()
self.processes.append(proc)
class Process(multiprocessing.Process):
"""Wrapper around multiprocessing.Process that uses
setproctitle to set the name of the process when running

View File

@ -118,7 +118,7 @@ def test_pool_raises_empty_exception_when_timeout(mock_queue):
@patch("multiprocessing.Process")
def test_process_group_instantiates_and_start_processes(mock_process):
from planetmint.utils import ProcessGroup
from tests.utils import ProcessGroup
def noop():
pass

View File

@ -2,6 +2,7 @@
# Planetmint and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
import multiprocessing
from hashlib import sha3_256
import base58
@ -197,3 +198,28 @@ def update_utxoset(connection, transaction):
if spent_outputs:
delete_unspent_outputs(connection, *spent_outputs)
store_unspent_outputs(connection, *[utxo._asdict() for utxo in transaction.unspent_outputs])
class ProcessGroup(object):
def __init__(self, concurrency=None, group=None, target=None, name=None, args=None, kwargs=None, daemon=None):
self.concurrency = concurrency or multiprocessing.cpu_count()
self.group = group
self.target = target
self.name = name
self.args = args or ()
self.kwargs = kwargs or {}
self.daemon = daemon
self.processes = []
def start(self):
for i in range(self.concurrency):
proc = multiprocessing.Process(
group=self.group,
target=self.target,
name=self.name,
args=self.args,
kwargs=self.kwargs,
daemon=self.daemon,
)
proc.start()
self.processes.append(proc)