How can i kill process that i have started with python

user11851036

So I made a program that opens tor browser and I need to kill that browser after some time how can I do that

I have tried to kill it with os.system and Linux commands

And this is command with whic I start the browser

    subprocess.call(['./start-tor-browser.desktop'])
Ammar Askar

Take a look at the documentation for subprocess.call, it says:

Run the command described by args. Wait for command to complete, then return the returncode attribute.

subprocess.call waits for the command to finish, i.e until Tor is closed in your case. Instead, you can use the lower-level Popen API directly which lets you control the process after it's been spawned.

In that case, your code would end up looking something like this:

p = subprocess.Popen(['./start-tor-browser.desktop'])
# ...
# do other stuff here
p.kill()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related