7 Replies - 1606 Views - Last Post: 11 May 2012 - 08:10 AMRate Topic:

Running Tor From Python

Posted 07 May 2012 - 09:49 PM

I am trying to write a Python script that runs Tor, waits until it is initialized, and then continues with execution. I am currently using the following code, but it could be quite unreliable depending on how long it takes Tor to initialize.

os.system("tor --quiet &")
time.sleep(7)
print "Done"

I need to start Tor as a background process because if I don't it will hang at the end of initialization. Can anyone point me in the right direction?

Re: Running Tor From Python

Posted 10 May 2012 - 01:54 AM

assuming that once tor is running after you enter the command to view the currently running processes on the system, you could check to see if tor is running in the processes and if it is then you know it has been launched and vice versa if it hasn't.

Re: Running Tor From Python

Posted 10 May 2012 - 02:34 AM

alexr1090, on 10 May 2012 - 03:54 AM, said:

assuming that once tor is running after you enter the command to view the currently running processes on the system, you could check to see if tor is running in the processes and if it is then you know it has been launched and vice versa if it hasn't.

here's one way to do that. This will work on linux. Just change the ps -A part of the code to whatever the command in windows is to see all of the running processes and it will work there too.

Re: Running Tor From Python

Posted 10 May 2012 - 08:03 AM

Thanks for the response alex, but this wouldn't work. I'm looking for a way to see if Tor has been fully initialized. It's possible for the Tor process to run without the program being fully initialized.

Re: Running Tor From Python

Posted 10 May 2012 - 05:38 PM

dboltz03, on 10 May 2012 - 10:03 AM, said:

Thanks for the response alex, but this wouldn't work. I'm looking for a way to see if Tor has been fully initialized. It's possible for the Tor process to run without the program being fully initialized.

Right. Whenever I run that strip of code I wrote earlier it says tor is running and it is as someone pointed out but it's not ready as you want it to be. After it says that tor is running though, I get some messages if it's the first time I'm initilizing tor. The last message I get is "May 10 19:26:45.939 [notice] Tor has successfully opened a circuit. Looks like client functionality is working." Does that mean tor is ready to use? Or if not does tor send any message that says when it's ready?