降低循环等待间隔

This commit is contained in:
g1879 2024-12-03 18:13:14 +08:00
parent 0d9951f516
commit e19b13734d
13 changed files with 32 additions and 32 deletions

View File

@ -45,7 +45,7 @@ class Chromium(object):
if browser_id in cls._BROWSERS:
r = cls._BROWSERS[browser_id]
while not hasattr(r, '_driver'):
sleep(.1)
sleep(.05)
return r
r = object.__new__(cls)
r._chromium_options = opt
@ -318,7 +318,7 @@ class Chromium(object):
while self.states.is_alive:
if tab in self._drivers:
break
sleep(.1)
sleep(.01)
else:
raise BrowserConnectError('浏览器已关闭')
tab = tab_type(self, tab)

View File

@ -199,7 +199,7 @@ class Driver(object):
def stop(self):
self._stop()
while self._handle_event_th.is_alive() or self._recv_th.is_alive():
sleep(.1)
sleep(.01)
return True
def _stop(self):

View File

@ -289,7 +289,7 @@ class ChromiumElement(DrissionElement):
if ele and (loc_data is None or _check_ele(ele, loc_data)):
return ele
sleep(.1)
sleep(.01)
return NoneElement(page=self.owner, method='offset()',
args={'locator': locator, 'offset_x': x, 'offset_y': y, 'timeout': timeout})
@ -451,7 +451,7 @@ class ChromiumElement(DrissionElement):
'&& this.naturalHeight > 0')
end_time = perf_counter() + timeout
while not self._run_js(js) and perf_counter() < end_time:
sleep(.1)
sleep(.05)
src = self.attr('href') if self.tag == 'link' else self.attr('src')
if not src:
@ -488,7 +488,7 @@ class ChromiumElement(DrissionElement):
break
except CDPError:
pass
sleep(.1)
sleep(.05)
if not result:
return None
@ -533,7 +533,7 @@ class ChromiumElement(DrissionElement):
'&& typeof this.naturalHeight != "undefined" && this.naturalHeight > 0')
end_time = perf_counter() + self.timeout
while not self._run_js(js) and perf_counter() < end_time:
sleep(.1)
sleep(.05)
if scroll_to_center:
self.scroll.to_see(center=True)
@ -905,7 +905,7 @@ class ShadowRoot(BaseElement):
end_time = perf_counter() + timeout
result = do_find()
while result is None and perf_counter() <= end_time:
sleep(.1)
sleep(.01)
result = do_find()
if result:
@ -1004,7 +1004,7 @@ def find_by_xpath(ele, xpath, index, timeout, relative=True):
end_time = perf_counter() + timeout
result = do_find()
while result is None and perf_counter() < end_time:
sleep(.1)
sleep(.01)
result = do_find()
if result:
@ -1043,7 +1043,7 @@ def find_by_css(ele, selector, index, timeout):
end_time = perf_counter() + timeout
result = do_find()
while result is None and perf_counter() < end_time:
sleep(.1)
sleep(.01)
result = do_find()
if result:

View File

@ -92,7 +92,6 @@ def set_browser_cookies(browser, cookies):
def set_tab_cookies(page, cookies):
suffixes_list = f"file:///{Settings.suffixes_list_path}"
for cookie in cookies_to_tuple(cookies):
cookie = format_cookie(cookie)
@ -117,7 +116,7 @@ def set_tab_cookies(page, cookies):
if not url.startswith('http'):
raise RuntimeError(f'未设置域名请设置cookie的domain参数或先访问一个网站。{cookie}')
ex_url = TLDExtract(suffix_list_urls=["https://publicsuffix.org/list/public_suffix_list.dat",
suffixes_list]).extract_str(url)
f"file:///{Settings.suffixes_list_path}"]).extract_str(url)
d_list = ex_url.subdomain.split('.')
d_list.append(f'{ex_url.domain}.{ex_url.suffix}' if ex_url.suffix else ex_url.domain)

View File

@ -150,7 +150,7 @@ class ChromiumBase(BasePage):
except:
timeout = end_time - perf_counter()
timeout = .5 if timeout <= 0 else timeout
sleep(.1)
sleep(.05)
else:
result = False
@ -223,7 +223,7 @@ class ChromiumBase(BasePage):
def _wait_to_stop(self):
end_time = perf_counter() + self.timeouts.page_load
while perf_counter() < end_time:
sleep(.1)
sleep(.02)
if self._ready_state in ('interactive', 'complete') and self._is_loading:
self.stop_loading()
@ -486,7 +486,7 @@ class ChromiumBase(BasePage):
if perf_counter() >= end_time:
return NoneElement(self) if index is not None else ChromiumElementsList(owner=self)
sleep(.1)
sleep(.01)
timeout = end_time - perf_counter()
timeout = .5 if timeout <= 0 else timeout
result = self.driver.run('DOM.performSearch', query=loc, _timeout=timeout, includeUserAgentShadowDOM=True)
@ -539,7 +539,7 @@ class ChromiumBase(BasePage):
self._run_cdp('Page.stopLoading')
end_time = perf_counter() + 5
while self._ready_state != 'complete' and perf_counter() < end_time:
sleep(.1)
sleep(.02)
except (PageDisconnectedError, CDPError):
pass
finally:
@ -693,7 +693,7 @@ class ChromiumBase(BasePage):
timeout = .1 if timeout <= 0 else timeout
end_time = perf_counter() + timeout
while not self._alert.activated and perf_counter() < end_time:
sleep(.1)
sleep(.01)
if not self._alert.activated:
return False
@ -744,7 +744,7 @@ class ChromiumBase(BasePage):
'complete') and not self._is_loading:
return True
sleep(.1)
sleep(.01)
try:
self.stop_loading()
@ -773,7 +773,7 @@ class ChromiumBase(BasePage):
print(f'重试{t + 1} {to_url}')
end_time1 = end_time - perf_counter()
while self._ready_state not in ('loading', 'complete') and perf_counter() < end_time1: # 等待出错信息显示
sleep(.1)
sleep(.01)
self.stop_loading()
continue

View File

@ -267,7 +267,7 @@ class ChromiumBase(BasePage):
...
@property
def session(self)->Session:
def session(self) -> Session:
"""返回用于转换模式或download的Session对象"""
...
@ -479,7 +479,8 @@ class ChromiumBase(BasePage):
def add_ele(self,
html_or_info: Union[str, Tuple[str, dict]],
insert_to: Union[ChromiumElement, str, Tuple[str, str], None] = None,
before: Union[ChromiumElement, str, Tuple[str, str], None] = None) -> ChromiumElement:
before: Union[ChromiumElement, str, Tuple[str, str], None] = None) -> Union[
ChromiumElement, ChromiumFrame]:
"""新建一个元素
:param html_or_info: 新元素的html文本或信息信息格式为(tag, {attr1: value, ...})
:param insert_to: 插入到哪个元素中可接收元素对象和定位符为None且为html添加到body不为html不插入

View File

@ -35,7 +35,7 @@ class ChromiumFrame(ChromiumBase):
if Settings.singleton_tab_obj and fid in cls._Frames:
r = cls._Frames[fid]
while not hasattr(r, '_type') or r._type != 'ChromiumFrame':
sleep(.1)
sleep(.01)
return r
r = object.__new__(cls)
cls._Frames[fid] = r

View File

@ -24,7 +24,7 @@ class ChromiumPage(ChromiumBase):
if browser.id in cls._PAGES:
r = cls._PAGES[browser.id]
while not hasattr(r, '_frame_id'):
sleep(.1)
sleep(.05)
return r
r = object.__new__(cls)

View File

@ -22,7 +22,7 @@ class ChromiumTab(ChromiumBase):
if Settings.singleton_tab_obj and tab_id in cls._TABS:
r = cls._TABS[tab_id]
while not hasattr(r, '_frame_id'):
sleep(.1)
sleep(.05)
return r
r = object.__new__(cls)
cls._TABS[tab_id] = r

View File

@ -191,7 +191,7 @@ class Listener(object):
if timeout is None:
while ((not targets_only and self._running_requests > limit)
or (targets_only and self._running_targets > limit)):
sleep(.1)
sleep(.01)
return True
end_time = perf_counter() + timeout
@ -199,7 +199,7 @@ class Listener(object):
if ((not targets_only and self._running_requests <= limit)
or (targets_only and self._running_targets <= limit)):
return True
sleep(.1)
sleep(.01)
else:
return False
@ -423,7 +423,7 @@ class DataPacket(object):
def wait_extra_info(self, timeout=None):
if timeout is None:
while self._responseExtraInfo is None:
sleep(.1)
sleep(.01)
return True
else:
@ -431,7 +431,7 @@ class DataPacket(object):
while perf_counter() < end_time:
if self._responseExtraInfo is not None:
return True
sleep(.1)
sleep(.01)
else:
return False

View File

@ -86,7 +86,7 @@ class Screencast(object):
if self._mode.startswith('js'):
self._owner._run_js('mediaRecorder.stop();', as_expr=True)
while not self._owner._run_js('return DrissionPage_Screencast_blob_ok;'):
sleep(.1)
sleep(.05)
blob = self._owner._run_js('return DrissionPage_Screencast_blob;')
uuid = self._owner._run_cdp('IO.resolveBlob', objectId=blob['result']['objectId'])['uuid']
data = self._owner._run_cdp('IO.read', handle=f'blob:{uuid}')['data']
@ -100,7 +100,7 @@ class Screencast(object):
else:
self._enable = False
while self._running:
sleep(.1)
sleep(.01)
if self._mode.endswith('imgs'):
return str(Path(self._path).absolute())

View File

@ -77,7 +77,7 @@ class Scroller(object):
end_time = perf_counter() + owner.timeout
while perf_counter() < end_time:
sleep(.1)
sleep(.02)
r = owner._run_cdp('Page.getLayoutMetrics')
x1 = r['layoutViewport']['pageX']
y1 = r['layoutViewport']['pageY']

View File

@ -469,7 +469,7 @@ class WindowSetter(object):
try:
return self._owner._run_cdp('Browser.getWindowForTarget')
except:
sleep(.1)
sleep(.02)
raise RuntimeError('获取窗口信息失败。')
def _perform(self, bounds):