1 #! /usr/bin/env python3
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 ## @file killSalome.py
26 # @brief Forcibly stop all running %SALOME sessions.
29 Forcibly stop all running SALOME sessions.
31 To stop all SALOME sessions, do the following:
39 from killSalome import killAllPorts
43 # pragma pylint: disable=invalid-name
49 from contextlib import suppress
52 from killSalomeWithPort import getPiDict, killMyPort, killUnkilledProcesses
56 Stop all running SALOME sessions owned by the current user.
58 # detect ports used by SALOME session and kill processes
59 for hidden in (True, False):
60 pidict_t = getPiDict(port='#####', hidden=hidden)
61 dir_pidict_t = osp.dirname(pidict_t)
62 fn_pidict_t = osp.basename(pidict_t).replace('#####', r'(\d*)')
63 fn_rex = re.compile('^{}'.format(fn_pidict_t))
64 with suppress(IOError):
65 for fname in os.listdir(dir_pidict_t):
66 m_res = fn_rex.match(fname)
68 killMyPort(m_res.group(1))
70 # kill possibly unkilled processes
71 killUnkilledProcesses()
73 # other clean-up actions
74 # - delete uri files needed by ompi-server
75 for path in glob(osp.join(osp.expanduser('~'), '.urifile_*')):
76 with suppress(IOError):
83 from argparse import ArgumentParser
84 parser = ArgumentParser(description='Forcibly stop all running SALOME sessions')
88 from salomeContextUtils import setOmniOrbUserPath
90 except Exception as exc: # pragma pylint: disable=broad-except
96 if __name__ == '__main__':