Link to home
Start Free TrialLog in
Avatar of Mehran Goudarzi
Mehran Goudarzi

asked on

killall tor && service tor start in Python

i want use this command on my Python script :

 killall tor  && service tor start 

Open in new window

  How can i do it on Python ?
ASKER CERTIFIED SOLUTION
Avatar of gelonida
gelonida
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mehran Goudarzi
Mehran Goudarzi

ASKER

what is different between  
subprocess.Popen

Open in new window

 and
subprocess.call

Open in new window

If you use subprocess.Popen, then the process is started, but python does not wait for it to be finished.

The equivalen with subprocess Popen would be.

import subprocess
proc1 = subprocess.Popen(["killall", "tor"])
returncode = proc1.wait()
if returncode == 0:
    proc2 = subprocess.Popen(["service", "tor", "start"])
    returncode = proc2.wait()

Open in new window


subprodcess.call() is just a shortcut.

if you use subprocess Popen without the wait function, then you might call
"service tor start" before "killall tor" has been finished.
and the python script would continue executing other python commands before any of the subprocesses had been finished.