Fix: missed doc in setup

Mod: adding pid file
New: cli kill command
This commit is contained in:
L-Nafaryus 2021-09-02 18:11:31 +05:00
parent c86d885ae4
commit 422806777e
No known key found for this signature in database
GPG Key ID: EF672A5303B2FA96
4 changed files with 44 additions and 2 deletions

View File

@ -147,6 +147,12 @@ def compute(stage, nprocs, force, update, params, path):
for param in params:
args.update(param)
###
logger.info("Writing pid ...")
with open(os.path.join(path, "anisotropy.pid"), "w") as io:
io.write(str(os.getpid()))
###
model = Anisotropy()
model.db = Database(env["db_name"], env["db_path"])
@ -247,6 +253,33 @@ def compute(stage, nprocs, force, update, params, path):
parallel(nprocs, queueargs, computeCase)
@anisotropy.command(
help = "Kill process by pid file"
)
@click.option(
"-P", "--path", "path",
default = os.getcwd(),
help = "Specify directory to use (instead of cwd)"
)
@click.argument("pidfile")
def kill(path, pidfile):
from anisotropy.salomepl.utils import SalomeManager
try:
with open(os.path.join(path, pidfile), "r") as io:
pid = io.read()
os.kill(int(pid), 9)
except FileNotFoundError:
click.echo(f"Unknown file { pidfile }")
except ProcessLookupError:
click.echo(f"Cannot find process with pid { pid }")
# TODO: killall method kills all salome instances. Not a good way
SalomeManager().killall()
@anisotropy.command(
help = "! Not a user command"
)

View File

@ -257,7 +257,7 @@ class Anisotropy(object):
*salomeargs,
timeout = self.env["salome_timeout"],
root = self.env["ROOT"],
logpath = os.path.join(casepath, "logs")
logpath = casepath
)

View File

@ -59,6 +59,10 @@ class SalomeManager(object):
return self.runner(["salome", "kill", str(self.__port or port)])
def killall(self):
return self.runner(["salome", "killall"])
def execute(self, scriptpath: str, *args, root: str = None, logpath: str = None, timeout: int = None, **kwargs):
if not root:
@ -97,6 +101,8 @@ class SalomeManager(object):
returncode = lastproc.returncode
if logpath:
os.makedirs(logpath, exist_ok = True)
with open(os.path.join(logpath, "salome.log"), "wb") as io:
io.write(out)
io.write(err)

View File

@ -50,7 +50,10 @@ def main():
],
data_files = [
("share/doc/anisotropy", findall("docs"))
("share/doc/anisotropy", findall("docs")),
("share/doc/anisotropy/source", findall("docs/source")),
("share/doc/anisotropy/source/static", findall("docs/source/static")),
("share/doc/anisotropy/source/notes", findall("docs/source/notes"))
],
package_data = {