0

我正在开发一个使用stem创建3个Tor实例的脚本,从stem教程“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

创建第一个实例后,将打印返回错误:

OSError: Process terminated: No, it's still there.  Exiting.
4

2 回答 2

1

launch_tor_with_config() 函数确实使用临时的新 torrc 文件启动 tor,一旦 tor 实例被杀死/停止,该文件就会被删除。但我注意到有一个锁定文件,就像您在中断 Linux 包管理器更新时拥有的那样,但它位于 ~/.tor/lck 启动新实例之前,请确保等待锁定文件出现,然后将其删除在您的脚本中,将成功创建多个 tor 实例。

于 2019-09-18T18:58:30.880 回答
0

只需为每个线程设置不同的“DataDirettory”。

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(),
                          )
于 2020-03-14T20:15:19.033 回答