X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2FaddToKillList.py;h=3f892e77283ea9441fb1ef3a4050bd8588eaedbd;hb=a4874256219c549a9b1ff740d549391c4bf2f25f;hp=06a32f46b4dbc81b2df4bfda25dc68b2e18b2ccd;hpb=1d633fa1c13b169da8b4f8a5cfad4587bf586b0b;p=modules%2Fkernel.git diff --git a/bin/addToKillList.py b/bin/addToKillList.py index 06a32f46b..3f892e772 100755 --- a/bin/addToKillList.py +++ b/bin/addToKillList.py @@ -1,6 +1,6 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE # # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -50,17 +50,18 @@ def addToKillList(command_pid, command, port=None): from killSalomeWithPort import getPiDict if port is None: port=findFileDict() filedict = getPiDict(port) + #filedict = getPiDict(port).encode() try: - with open(filedict, 'r') as fpid: + with open(filedict, 'rb') as fpid: process_ids=pickle.load(fpid) - except: + except Exception: process_ids=[] pass # check if PID is already in dictionary already_in=False for process_id in process_ids: - for pid in list(process_id.keys()): + for pid in process_id: if int(pid) == int(command_pid): already_in=True break @@ -71,16 +72,16 @@ def addToKillList(command_pid, command, port=None): # add process to the dictionary if not already_in: import types - if type(command) == list: command=" ".join([str(c) for c in command]) + if isinstance(command, list): command=" ".join([str(c) for c in command]) command=command.split()[0] try: if verbose(): print("addToKillList: %s : %s" % ( str(command_pid), command )) process_ids.append({int(command_pid): [command]}) dir = os.path.dirname(filedict) if not os.path.exists(dir): os.makedirs(dir, 0o777) - with open(filedict,'w') as fpid: + with open(filedict,'wb') as fpid: pickle.dump(process_ids, fpid) - except: + except Exception: if verbose(): print("addToKillList: can not add command %s : %s to the kill list" % ( str(command_pid), command )) pass pass @@ -102,9 +103,9 @@ def killList(port=None): if not os.path.exists(filedict): filedict = getPiDict(port, hidden=False) try: - with open(filedict, 'r') as fpid: + with open(filedict, 'rb') as fpid: process_ids=pickle.load(fpid) - except: + except Exception: process_ids=[] pass # kill processes @@ -113,7 +114,7 @@ def killList(port=None): for pid, cmd in list(process_id.items()): try: os.kill(int(pid),signal.SIGKILL) - except: + except Exception: print(" ------------------ process %s : %s inexistant"% (pid, cmd[0])) pass pass @@ -123,6 +124,8 @@ def killList(port=None): pass if __name__ == "__main__": - if verbose(): print(sys.argv) + if verbose(): print(sys.argv[1:]) + if len(sys.argv) < 3: + sys.exit(-1) addToKillList(sys.argv[1], sys.argv[2]) pass