mirror of
https://github.com/planetmint/planetmint.git
synced 2025-07-09 05:52:30 +00:00
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:
parent
6d166747d1
commit
6aa37cf6a6
@ -10,31 +10,6 @@ import multiprocessing
|
|||||||
import setproctitle
|
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):
|
class Process(multiprocessing.Process):
|
||||||
"""Wrapper around multiprocessing.Process that uses
|
"""Wrapper around multiprocessing.Process that uses
|
||||||
setproctitle to set the name of the process when running
|
setproctitle to set the name of the process when running
|
||||||
|
@ -118,7 +118,7 @@ def test_pool_raises_empty_exception_when_timeout(mock_queue):
|
|||||||
|
|
||||||
@patch("multiprocessing.Process")
|
@patch("multiprocessing.Process")
|
||||||
def test_process_group_instantiates_and_start_processes(mock_process):
|
def test_process_group_instantiates_and_start_processes(mock_process):
|
||||||
from planetmint.utils import ProcessGroup
|
from tests.utils import ProcessGroup
|
||||||
|
|
||||||
def noop():
|
def noop():
|
||||||
pass
|
pass
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
# Planetmint and IPDB software contributors.
|
# Planetmint and IPDB software contributors.
|
||||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
import multiprocessing
|
||||||
from hashlib import sha3_256
|
from hashlib import sha3_256
|
||||||
|
|
||||||
import base58
|
import base58
|
||||||
@ -197,3 +198,28 @@ def update_utxoset(connection, transaction):
|
|||||||
if spent_outputs:
|
if spent_outputs:
|
||||||
delete_unspent_outputs(connection, *spent_outputs)
|
delete_unspent_outputs(connection, *spent_outputs)
|
||||||
store_unspent_outputs(connection, *[utxo._asdict() for utxo in transaction.unspent_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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user