Back to index

salome-kernel  6.5.0
Functions
addToKillList Namespace Reference

Functions

def findFileDict
 adds to the kill list of SALOME one more process ##########
def addToKillList
def killList

Function Documentation

def addToKillList.addToKillList (   command_pid,
  command,
  port = None 
)
Add the process to the SALOME processes dictionary file.
Parameters:
- command_pid : command PID
- command     : command (string or list of strings)
- [port]      : SALOME port number; if this parameter is None (default),
it is detected automatically

Definition at line 40 of file addToKillList.py.

00040 
00041 def addToKillList(command_pid, command, port=None):
00042     """
00043     Add the process to the SALOME processes dictionary file.
00044     Parameters:
00045     - command_pid : command PID
00046     - command     : command (string or list of strings)
00047     - [port]      : SALOME port number; if this parameter is None (default),
00048     it is detected automatically
00049     """
00050     # retrieve current processes dictionary
00051     from killSalomeWithPort import getPiDict
00052     if port is None: port=findFileDict()
00053     filedict=getPiDict(port)
00054     try:
00055         fpid=open(filedict, 'r')
00056         process_ids=pickle.load(fpid)
00057         fpid.close()
00058     except:
00059         process_ids=[]
00060         pass
00061     # check if PID is already in dictionary
00062     already_in=False
00063     for process_id in process_ids:
00064         for pid, cmd in process_id.items():
00065             if int(pid) == int(command_pid):
00066                 already_in=True
00067                 break
00068             pass
00069         if already_in: break
00070         pass
00071     # add process to the dictionary
00072     if not already_in:
00073         import types
00074         if type(command) == types.ListType: command=" ".join([str(c) for c in command])
00075         command=command.split()[0]
00076         try:
00077             if verbose(): print "addToKillList: %s : %s" % ( str(command_pid), command )
00078             process_ids.append({int(command_pid): [command]})
00079             dir = os.path.dirname(filedict)
00080             if not os.path.exists(dir): os.makedirs(dir, 0777)
00081             fpid = open(filedict,'w')
00082             pickle.dump(process_ids, fpid)
00083             fpid.close()
00084         except:
00085             if verbose(): print "addToKillList: can not add command %s : %s to the kill list" % ( str(command_pid), command )
00086             pass
00087         pass
00088     pass

Here is the call graph for this function:

adds to the kill list of SALOME one more process ##########

Detect current SALOME session's port number.
Returns port number.

Definition at line 30 of file addToKillList.py.

00030 
00031 def findFileDict():
00032     """
00033     Detect current SALOME session's port number.
00034     Returns port number.
00035     """
00036     from salome_utils import getPortNumber
00037     port = getPortNumber()
00038     if verbose(): print "myport = ", port
00039     return port
    

Here is the call graph for this function:

Here is the caller graph for this function:

def addToKillList.killList (   port = None)
Kill all the processes listed in the SALOME processes dictionary file.
- [port]      : SALOME port number; if this parameter is None (default),
it is detected automatically

Definition at line 89 of file addToKillList.py.

00089 
00090 def killList(port=None):
00091     """
00092     Kill all the processes listed in the SALOME processes dictionary file.
00093     - [port]      : SALOME port number; if this parameter is None (default),
00094     it is detected automatically
00095     """
00096     # retrieve processes dictionary
00097     from killSalomeWithPort import getPiDict
00098     if port is None: port=findFileDict()
00099     # new-style dot-prefixed pidict file
00100     filedict=getPiDict(port, hidden=True)
00101     # provide compatibility with old-style pidict file (not dot-prefixed)
00102     if not os.path.exists(filedict): filedict = getPiDict(port, hidden=False)
00103     try:
00104         fpid=open(filedict, 'r')
00105         process_ids=pickle.load(fpid)
00106         fpid.close()
00107     except:
00108         process_ids=[]
00109         pass
00110     # kill processes
00111     for process_id in process_ids:
00112         #print process_id
00113         for pid, cmd in process_id.items():
00114             print "stop process %s : %s"% (pid, cmd[0])
00115             try:
00116                 os.kill(int(pid),signal.SIGKILL)
00117             except:
00118                 print "  ------------------ process %s : %s inexistant"% (pid, cmd[0])
00119                 pass
00120             pass
00121         pass
00122     # remove processes dictionary file
00123     os.remove(filedict)
00124     pass

Here is the call graph for this function: