0

I'd like to end a process after certain conditions are met within a script. like this:

import psutil
PROCNAME = "standard.exe"

    for proc in psutil.process_iter():
        if proc.name() == PROCNAME:
            proc.kill()

I can run this standalone script (processkiller.py) in Spyder and it works but I'd would like to run this script from another script, like this:

os.system("C:\\Users\\s086372\\Desktop\\results\ProcessKiller.py")

This doesn't work, any suggestions? I'm still a beginner who is using simple codes to script engineering simulations.

the mdb.jobs.kill() within abaqus doesn't work, it's bugging, so I have to manually kill the process in some way.

isok89
  • 41
  • 1
  • 5

1 Answers1

2

Use:

os.system("python C:\\Users\\s086372\\Desktop\\results\ProcessKiller.py")

You have to pass the .py to the python interpreter.

  • It doesn't work for me, I can run my script from Spyder and it will end the process but not from my mainscript: os.system("python C:\\Users\\s086372\\Desktop\results\ProcessKiller.py") print 'Process has been killed' I do get the print message afterwards, but no errors – isok89 Aug 03 '16 at 16:12
  • Maybe you don't have the rights to kill the process, try: os.system("runas /noprofile /user:Administrator python C:\\Users\\s086372\\Desktop\\results\ProcessKiller.py") – William Guimont Aug 03 '16 at 16:40
  • Try adding : "proc.terminate()" juste before "proc.kill()" – William Guimont Aug 03 '16 at 17:44
  • I will try this, it really bugs me that the script works independently but somehow it doesn't if I call it from my main script. I have to add that my mainscript doesnt run the processkiller.py at all. I added a print message to the proceskiller.py which doesnt show up – isok89 Aug 03 '16 at 19:27
  • Ok this didn't work either, now I managed to import the psutil module into the abaqus scripting environment, so I have just one script. PROCNAME = "standard.exe" for proc in psutil.process_iter(): print ('Entered the For loop ') if proc.name() == PROCNAME: print ('Entered the if statement ') proc.terminate() proc.kill() I do enter the for loop since I get the print message, but the script doesn't pass the 'IF' statement – isok89 Aug 03 '16 at 21:35