I am developing a script that creates 3 Tor instances using stem, from stem tutorial "to Russia with love".
def print_bootstrap_lines(line):
if "Bootstrapped " in line:
print(term.format(line, term.Color.BLUE))
def main():
SocksPort=9050
#print(str(SocksPort))
i=0
while i<2:
tor_process=stem.process.launch_tor_with_config(
config={
'SocksPort':str(SocksPort),
'ControlPort':str(SocksPort+1),
'ExitNodes':'{ru}',
'StrictNodes':'1',},
init_msg_handler=print_bootstrap_lines,
)
SocksPort=SocksPort+2
i=i+1
after the creation of the first instance, a return error is printed:
OSError: Process terminated: No, it's still there. Exiting.
launch_tor_with_config() function does launch tor with a temporary new torrc file which gets deleted once the tor instance is killed/stopped. but i noticed that there is a lock file, like the one you have when you interrupt the Linux package manager updates, but it is located in ~/.tor/lck
so before starting the new instance make sure to wait for the lock file to appear, then delete it from within your script, and the multiple tor instances will be created successfully.
just set "DataDirettory" different for each thread.
self.tor_process = stem.process.launch_tor_with_config(
config={
'SocksPort':str(self.SocksPort),
'ControlPort':str(self.ControlPort),
'ExitNodes':self.ExitNodes,
'StrictNodes':self.StrictNodes,
'DataDirectory': path,
'Log': [
'NOTICE stdout',
'ERR file /tmp/tor_error_log',
],
},
#init_msg_handler=self.print_bootstrap_lines(),
)
just add any data directory like what a friend (lacopoOrtis) has written in above answer
make sure you have installed stem by using this command in terminal:
pip install stem
and you have imported it in your py file like this
import stem.process
path in 'DataDirectory' can be any path like c:/datadirectories/1/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.