Kill instance of salome when running in TUI [killSalome]

Hello,
when running a script in TUI by “salome -t script.py” if we want to kill salome after the script is finished,
I normally added at the end of the script

import killSalome
killSalome.killAllPorts()

but this will kill all the instances of salome if I am correctly, so if we are running multiple scripts in the background it will be problematic, is there any way to kill the actual instance?
i found “killSalome.killMyPort” and tried to use

import killSalome
killSalome.killMyPort()

without succes, as the instance stills runs. any solution for this?
EDIT:
it looks that this workaround solves the problem I was having, by adding at the end of the script:

import killSalome os
killSalome.killMyPort(os.getenv('NSPORT'))

best regards,
F.

1 Like

Hello,
I was previously using this approach which worked correctly, but now I was trying with salome 9.12 and using subprocess in python, and I am having issues getting the port number.
the command I am running inside my main python script is the following:

command=['/home/user/Programs/Salome/SALOME-master/mesa_salome', ' -t -w1', '/home/user/Desktop/mesh.py', 'args:pathToCurrentFolder=/home/franco/Downloads/Part/,name_0=/home/franco/Downloads/Part/1.step,name_1=/home/franco/Downloads/Part/2.step,name_2=/home/franco/Downloads/Part/3.step']
result = subprocess.run(command, capture_output=True, text=True)

but if I do this, when I do:

import os
os.getenv('NSPORT')

I get None, so killSalome.killMyPort(os.getenv('NSPORT')) does not work. I run os.environ.keys() in hope that there was a ‘PORT’ something variable but the only ones that had PORT on it were:

'IMPORTLIB_METADATA_ROOT_DIR'
'IMPORTLIB_RESOURCES_ROOT_DIR'
'SPHINXCONTRIB_WEBSUPPORT_ROOT_DIR'

for the moment I can do with killAllPorts but in cases where I have other projects running at the same time this will be problematic.
how can I run a script and kill it when it finishes? (same behavior as it was with the last script) ie.,

import killSalome, os
killSalome.killMyPort(os.getenv('NSPORT'))

regards,

Hi Franco,

if you want to quit SALOME at the end of your script, you can simply add :

import sys
sys.exit()

Or you can do like at the end of runSalome.py:

import salome
from salome_utils import getPortNumber
from killSalomeWithPort import killProcessSSL
port = getPortNumber()
session_pid=salome.myStudy.getPID()
killProcessSSL(port,[session_pid])

Christophe

1 Like