+# (1) If --shutdown-servers option is set to 1, session close procedure is
+# called twice: first explicitly by salome command, second by automatic
+# atexit to handle Ctrl-C. During second call, LCC does not exist anymore and
+# a RuntimeError is raised; we explicitly exit this function with code 0 to
+# prevent parent thread from crashing.
+
+def __killMyPort(port, filedict):
+ # bug fix: ensure port is an integer
+ if port:
+ port = int(port)
+
+ try:
+ with open(filedict, 'rb') as fpid:
+ process_ids=pickle.load(fpid)
+ for process_id in process_ids:
+ for pid, cmd in list(process_id.items()):
+ if verbose(): print("stop process %s : %s"% (pid, cmd[0]))
+ try:
+ from salome_utils import killpid
+ killpid(int(pid))
+ except:
+ if verbose(): print(" ------------------ process %s : %s not found"% (pid, cmd[0]))
+ pass
+ pass # for pid ...
+ pass # for process_id ...
+ # end with
+ except:
+ print("Cannot find or open SALOME PIDs file for port", port)
+ pass
+ os.remove(filedict)
+ pass
+#
+
+def __guessPiDictFilename(port):
+ from salome_utils import getShortHostName, getHostName
+ filedicts = [
+ # new-style dot-prefixed pidict file
+ getPiDict(port, hidden=True),
+ # provide compatibility with old-style pidict file (not dot-prefixed)
+ getPiDict(port, hidden=False),
+ # provide compatibility with old-style pidict file (short hostname)
+ getPiDict(port, hidden=True, hostname=getShortHostName()),
+ # provide compatibility with old-style pidict file (not dot-prefixed, short hostname
+ getPiDict(port, hidden=False, hostname=getShortHostName()),
+ # provide compatibility with old-style pidict file (long hostname)
+ getPiDict(port, hidden=True, hostname=getHostName()),
+ # provide compatibility with old-style pidict file (not dot-prefixed, long hostname)
+ getPiDict(port, hidden=False, hostname=getHostName())
+ ]
+
+ log_msg = ""
+ for filedict in filedicts:
+ log_msg += "Trying %s..."%filedict
+ if os.path.exists(filedict):
+ log_msg += " ... OK\n"
+ break
+ else:
+ log_msg += " ... not found\n"
+
+ if verbose():
+ print(log_msg)
+
+ return filedict
+#