【问题标题】:multiple Tor instances through stem通过 stem 的多个 Tor 实例
【发布时间】:2019-09-16 11:26:05
【问题描述】:

我正在开发一个使用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.

【问题讨论】:

    标签: python-3.x tor stem


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      只需为每个线程设置不同的“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(),
                                )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-08
        • 2015-04-22
        • 1970-01-01
        • 2015-04-23
        • 1970-01-01
        • 1970-01-01
        • 2013-07-01
        相关资源
        最近更新 更多