From a7873dfe91ab0eb1ecb5b1b2c0d6ca40256d7fd6 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Tue, 26 Jul 2022 11:38:22 +0200 Subject: [PATCH] check accepted contact before sending request --- src/workers/TlsPlaywright.py | 37 +++-------------------------------- src/workers/commandor_page.py | 4 ++-- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/workers/TlsPlaywright.py b/src/workers/TlsPlaywright.py index 798355f..c6e30d7 100644 --- a/src/workers/TlsPlaywright.py +++ b/src/workers/TlsPlaywright.py @@ -3,38 +3,7 @@ import threading from playwright.sync_api import sync_playwright -class OnlyOne: - class __OnlyOne: - def __init__(self, arg): - self.val = arg - - def __str__(self): - return repr(self) + self.val - - instance = None - - def __init__(self, arg): - if not OnlyOne.instance: - OnlyOne.instance = OnlyOne.__OnlyOne(arg) - else: - OnlyOne.instance.val = arg - - def __getattr__(self, name): - return getattr(self.instance, name) - - -class TlsPlaywright(): +class TlsPlaywright(threading.local): # private nested inner class - class __TlsPlaywrightSingleton(threading.local): - def __init__(self) -> None: - self.playwright = sync_playwright().start() - print("创建浏览器实例,线程: ", threading.current_thread().name) - - playwright = None - - def __init__(self): - if not TlsPlaywright.playwright: - TlsPlaywright.playwright = TlsPlaywright.__TlsPlaywrightSingleton().playwright - - def __getattr__(self, name): - return getattr(self.playwright, name) + def __init__(self) -> None: + self.playwright = sync_playwright().start() diff --git a/src/workers/commandor_page.py b/src/workers/commandor_page.py index ed37f19..cdc45f5 100644 --- a/src/workers/commandor_page.py +++ b/src/workers/commandor_page.py @@ -87,7 +87,7 @@ class CommandorPage: self.logger.info("will close timeout modem") self.termine() - def _run(self, e: threading.Event, proxy): + def _run(self, proxy): self.logger.info("will start browser") self.on_success_listener = on_success # reset otp_value to None @@ -153,7 +153,7 @@ class CommandorPage: def start_page(self, proxy): e = threading.Event() - self._run(e, proxy) + self._run(proxy) def _on_page_loaded(self): self.logger.info("页面加载完毕")