Mod: working multiprocessing mode

This commit is contained in:
L-Nafaryus 2021-08-30 21:05:11 +05:00
parent 5119e04a09
commit 402e763305
No known key found for this signature in database
GPG Key ID: C76D8DCD2727DBB7
3 changed files with 39 additions and 17 deletions

View File

@ -14,9 +14,27 @@ from anisotropy.core.models import (
Mesh, SubMesh, MeshResult, Mesh, SubMesh, MeshResult,
Flow, FlowApproximation, FlowResult Flow, FlowApproximation, FlowResult
) )
from peewee import OperationalError
logger = logging.getLogger(env["logger_name"]) logger = logging.getLogger(env["logger_name"])
setupLogger(logger, logging.INFO, env["LOG"]) #setupLogger(logger, logging.INFO, env["LOG"])
# NOTE: Temporary solution for multiprocessing mode when database is locked
def tryUntilDone(func):
def inner(*args, **kwargs):
done = False
while not done:
try:
ret = func(*args, **kwargs)
done = True
except OperationalError:
pass
return ret
return inner
class Database(object): class Database(object):
@ -155,20 +173,21 @@ class Database(object):
) )
) )
structureID = self._updateStructure(params["structure"], query) structureID = tryUntilDone(self._updateStructure)(params["structure"], query)
meshID = self._updateMesh(params["mesh"], query, structureID) meshID = tryUntilDone(self._updateMesh)(params["mesh"], query, structureID)
for submeshParams in params.get("submesh", []): for submeshParams in params.get("submesh", []):
self._updateSubMesh(submeshParams, query, meshID) tryUntilDone(self._updateSubMesh)(submeshParams, query, meshID)
self._updateMeshResult(params.get("meshresult", {}), query, meshID) tryUntilDone(self._updateMeshResult)(params.get("meshresult", {}), query, meshID)
flowID = self._updateFlow(params["flow"], query, structureID) flowID = tryUntilDone(self._updateFlow)(params["flow"], query, structureID)
self._updateFlowApproximation(params.get("flowapprox", {}), query, flowID) tryUntilDone(self._updateFlowApproximation)(params.get("flowapprox", {}), query, flowID)
tryUntilDone(self._updateFlowResult)(params.get("flowresult", {}), query, flowID)
self._updateFlowResult(params.get("flowresult", {}), query, flowID)
def _updateStructure(self, src: dict, queryMain) -> int: def _updateStructure(self, src: dict, queryMain) -> int:
raw = deepcopy(src) raw = deepcopy(src)

View File

@ -250,13 +250,14 @@ class Anisotropy(object):
path path
] ]
manager = salomepl.utils.SalomeManager() manager = salomepl.utils.SalomeManager()
casepath = self.getCasePath(path)
return manager.execute( return manager.execute(
scriptpath, scriptpath,
*salomeargs, *salomeargs,
timeout = self.env["salome_timeout"], timeout = self.env["salome_timeout"],
root = self.env["ROOT"], root = self.env["ROOT"],
logpath = self.env["LOG"] logpath = os.path.join(casepath, "logs")
) )

View File

@ -18,7 +18,7 @@ class CustomFormatter(logging.Formatter):
red = "\x1b[31;21m" red = "\x1b[31;21m"
bold_red = "\x1b[31;1m" bold_red = "\x1b[31;1m"
reset = "\x1b[0m" reset = "\x1b[0m"
format = "[ %(asctime)s ] [ %(levelname)s ] %(message)s" format = "[ %(asctime)s ] [ %(processName)s ] [ %(levelname)s ] %(message)s"
formats = { formats = {
logging.DEBUG: grey + format + reset, logging.DEBUG: grey + format + reset,
@ -41,12 +41,14 @@ class CustomFormatter(logging.Formatter):
def setupLogger(logger, level: int, filepath: str = None): def setupLogger(logger, level: int, filepath: str = None):
"""Applies settings to logger """Applies settings to logger
:param logger: Instance of :class:`logging.Logger` :param logger:
:type logger: Instance of :class:`logging.Logger` Instance of :class:`logging.Logger`
:param level: Logging level (logging.INFO, logging.WARNING, ..)
:type level: int :param level:
:param filepath: Path to directory Logging level (logging.INFO, logging.WARNING, ..)
:type filepath: str, optional
:param filepath:
Path to directory
""" """
logger.handlers = [] logger.handlers = []
logger.setLevel(level) logger.setLevel(level)
@ -215,7 +217,7 @@ def queue(cmd, qin, qout, *args):
break break
# Execute command # Execute command
res = cmd(var, *args) res = cmd(*var, *args)
# Put results to the queue # Put results to the queue
qout.put((pos, res)) qout.put((pos, res))