]> SALOME platform Git repositories - modules/kernel.git/blob - src/Launcher/Test/launcher_use_case.py
Salome HOME
Compilation under Windows: add missing header
[modules/kernel.git] / src / Launcher / Test / launcher_use_case.py
1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2018-2021  CEA/DEN, EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 # classic use case of a job
23 import os
24 import salome
25 import tempfile
26 import time
27 import sys
28
29 if __name__ == '__main__':
30   salome.salome_init()
31   launcher = salome.naming_service.Resolve('/SalomeLauncher')
32   job_params = salome.JobParameters()
33   job_params.resource_required = salome.ResourceParameters()
34   job_params.resource_required.name = "localhost"
35   job_params.resource_required.nb_proc = 1 # slurm: --ntasks
36
37   job_params.job_type = "command"
38   #cwd = os.getcwd()
39   cwd = sys.argv[1]
40   case_dir = tempfile.mkdtemp(prefix="test")
41   job_params.local_directory = cwd
42   job_params.job_file = "command.sh"
43   job_params.work_directory = os.path.join(case_dir, "run")
44   job_params.result_directory = os.path.join(case_dir, "result")
45   job_params.out_files = ["result.txt"]
46   job_params.wckey="P11U5:CARBONES"
47   job_params.job_name = "MyJob"
48   job_id = launcher.createJob(job_params)
49   launcher.launchJob(job_id)
50   job_string = launcher.dumpJob(job_id)
51   jobState = launcher.getJobState(job_id)
52   while jobState != 'FINISHED' and jobState != 'FAILED':
53       time.sleep(1)
54       jobState = launcher.getJobState(job_id)
55   launcher.getJobResults(job_id, '')
56   launcher.getJobWorkFile(job_id, "result.txt", '')
57   launcher.clearJobWorkingDir(job_id)
58   launcher.removeJob(job_id)
59   new_id = launcher.restoreJob(job_string)
60   job_params_bis = launcher.getJobParameters(new_id)
61   jobState = launcher.getJobState(new_id)
62   launcher.removeJob(new_id)
63   launcher.saveJobs(os.path.join(case_dir,"savejobs.xml"))