-1

in my script, i call an app from os.system()

command = f"python -m snakeviz {filename}"
os.system(command)

the problem is that this application is freezing the console, therefore freezing my python plugin.

we cannot input anything, ("exit" command won't work) the only way to close the terminal is by running CTRL+C shortcut, and the terminal might be hidden..

this app has no reason to keep running it just open a webpage, how can I force quit the command, without losing the rest of my script?

DB3D
  • 186
  • 1
  • 12
  • Does this answer your question? [Opposite of os.system(), closing a python program](https://stackoverflow.com/questions/49640641/opposite-of-os-system-closing-a-python-program) – mkrieger1 Sep 05 '22 at 23:17
  • like so ? `terminal = subprocess.run([command]) ; terminal.terminate()` because it did not work – DB3D Sep 05 '22 at 23:21
  • I don't know what "did not work" means. – mkrieger1 Sep 05 '22 at 23:23
  • i'm sorry, i meant, that `subprocess.run()` is much more complicated to run than `os.system` which just take a piece of string – DB3D Sep 05 '22 at 23:23
  • You can make `subprocess.run()` "just take a piece of string" also, and it gives you the ability to manage the child process, which `os.system` does not. – larsks Sep 06 '22 at 02:13

1 Answers1

-1

Whatever i did, the command froze my python plugin

I needed to open another process with Open() and need shlex to encrypt the command line to whatever this subprocess module need

command = f"python -m snakeviz myfile.log"
subprocess.Popen(shlex.split(command))
DB3D
  • 186
  • 1
  • 12
  • You could have just passed the command and its arguments as a list of strings instead of using `shlex.split`. – mkrieger1 Sep 06 '22 at 11:03