如何在多线程中使用pyngrok?

How to use pyngrok with multi-threading?

我正在尝试 运行 一个具有 3 个线程的 python 脚本,其中一个是使用线程模块使用 pyngrok 将即将到来的连接端口转发到本地主机,但问题是每当ngrok 服务器启动它挂起所有其他线程...

    def CreateTunnel(self):
        try:
            ngrok.set_auth_token(self.AuthToken)

            print(f"{Fore.GREEN}[+] Opening TCP tunnel {Style.RESET_ALL}")
            tunnel = ngrok.connect(addr=self.port, proto="tcp")

            print(f"{Fore.GREEN}[+] Public URL:{Style.RESET_ALL} {Fore.CYAN}{ngrok.get_tunnels()[0]}{Style.RESET_ALL}")
            ngrok_proc = ngrok.get_ngrok_process()
            self.pub_url = tunnel.public_url.split("tcp://")[1]
            self.ngrokPort = tunnel.public_url.split("tcp://")[1].split(":")[1]

            ngrok_proc.proc.wait()  # Hangs the process and other threads stops execution

如何 运行 3 个线程同步? 或者我如何在不需要使用 proc.wait()?

的情况下设置 ngrok 服务器

线程的调用方式如下:

def Threads(self):
        # Adding them to a list
        if self.ngrok:
            self.jobs.append(th(target=self.CreateTunnel()))

        self.jobs.append(th(target=self.listen()))
        self.jobs.append(th(target=self.brute()))

        # Starting them
        for job in self.jobs:
            th.setDaemon(True)
            th.start()

看看这个

def Threads(self):
    # Adding them to a list
    if self.ngrok:
        self.jobs.append(th(target=self.CreateTunnel()))

    self.jobs.append(th(target=self.listen()))
    #self.jobs.append(th(target=self.brute()))

    # Starting them
    for job in self.jobs:
        th.setDaemon(True)
        th.start()


def CreateTunnel(self):
    try:
        ngrok.set_auth_token(self.AuthToken)

        print(f"{Fore.GREEN}[+] Opening TCP tunnel {Style.RESET_ALL}")
        tunnel = ngrok.connect(addr=self.port, proto="tcp")

        print(f"{Fore.GREEN}[+] Public URL:{Style.RESET_ALL} {Fore.CYAN}{ngrok.get_tunnels()[0]}{Style.RESET_ALL}")
        ngrok_proc = ngrok.get_ngrok_process()
        self.pub_url = tunnel.public_url.split("tcp://")[1]
        self.ngrokPort = tunnel.public_url.split("tcp://")[1].split(":")[1]

        ngrok_proc.proc.wait()  # Hangs the process and other threads stops execution

祝你好运‍♂️‍♂️