我正在嘗試運行具有 3 個執行緒的 python 腳本,其中一個是使用執行緒模塊使用 pyngrok 將即將到來的連接埠轉發到 localhost,但問題是每當 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()
uj5u.com熱心網友回復:
看一下這個
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
祝你好運?????♂??????♂?
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/412307.html
標籤:
