在无头模式下使用ChromeDriver和Chrome浏览器,并使用--disable-gpu和--user-data-dir参数,GPU进程已经崩溃了x次(s)错误。

问题描述 投票:0回答:1

我是用硒来打开一个网站。具体来说。

https://storage.googleapis.com/tfjs-models/demos/posenet/camera.html

但是当它用 无头模式它显示以下错误。

[0513/155639.694:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 1 time(s)

DevTools listening on ws://127.0.0.1:6573/devtools/browser/58f34b20-1a05-4bf0-8e64-1b5a5028b1f6
[0513/155639.710:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5)
[0513/155639.710:ERROR:cache_util.cc(138)] Unable to move cache folder C:/Users/Tazim Fatima/AppData/Local/Google/Chrome/User Data\Default\GPUCache to C:/Users/Tazim Fatima/AppData/Local/Google/Chrome/User Data\Default\old_GPUCache_000
[0513/155639.710:ERROR:disk_cache.cc(184)] Unable to create cache
[0513/155639.710:ERROR:shader_disk_cache.cc(606)] Shader Cache Creation failed: -2
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 2 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 3 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 4 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 5 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 6 time(s)
[0513/155639.725:ERROR:browser_gpu_channel_host_factory.cc(153)] Failed to launch GPU process.
[0513/155642.754:ERROR:service_worker_storage.cc(1624)] Failed to delete the database: Database IO error`enter code here`

经过大量的搜索,我试过了:

options.add_argument("--disable-user-media-security=true")
options.add_argument('--headless')
options.add_argument("--no-sandbox")  
options.add_argument("--use-fake-ui-for-media-stream")
options.add_argument("--disable-gpu")
options.add_argument("--disable-software-rasterizer")
options.add_argument('--disable-gpu')
options.add_argument("--window-size=1280,1024")
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--ignore-gpu-blacklist')
options.add_argument('--use-gl')
options.add_argument("--user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data")

driver = webdriver.Chrome(options=options)
driver.maximize_window()
driver.set_window_size(1200, 600)
driver.set_window_size(1280, 1024)
driver.get("https://storage.googleapis.com/tfjs-models/demos/posenet/camera.html")

当然不是一次使用所有的参数,而是在不同的时间使用不同的参数块。不过有一点需要注意的是,当我使用参数 --无沙盒,错误变为

DevTools listening on ws://127.0.0.1:1849/devtools/browser/426a187c-243f-42e3-a0b7-60c4f8dc73b2
[0513/163007.734:ERROR:gles2_cmd_decoder.cc(3610)] ContextResult::kFatalFailure: fail_if_major_perf_caveat + swiftshader
[0513/163007.742:ERROR:gles2_cmd_decoder.cc(3610)] ContextResult::kFatalFailure: fail_if_major_perf_caveat + swiftshader
[0513/163007.754:ERROR:gles2_cmd_decoder.cc(3610)] ContextResult::kFatalFailure: fail_if_major_perf_caveat + swiftshader
[0513/163007.758:INFO:CONSOLE(20)] "Initialization of backend webgl failed", source: https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js (20)
[0513/163007.758:INFO:CONSOLE(20)] "Error: WebGL is not supported on this device
    at new e (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:294522)
    at Object.factory (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:346621)
    at t.initializeBackend (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:43098)
    at t.initializeBackendsAndReturnBest (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:44537)
    at t.get [as backend] (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:41137)
    at t.makeTensor (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:48217)
    at Tn (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:81890)
    at Dn (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:81021)
    at o (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:491592)
    at Object.Pp [as decodeWeights] (https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js:20:491626)", source: https://storage.googleapis.com/tfjs-models/demos/posenet/camera.cb338cd2.js (20)

而且还能用。但与非无头模式相比,它是非常非常慢。

而且我不能用速度进行交易。我怎样才能解决这个问题?

python selenium selenium-webdriver selenium-chromedriver google-chrome-headless
1个回答
0
投票

这个错误信息...

[0513/155639.710:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5)
[0513/155639.710:ERROR:cache_util.cc(138)] Unable to move cache folder C:/Users/Tazim Fatima/AppData/Local/Google/Chrome/User Data\Default\GPUCache to C:/Users/Tazim Fatima/AppData/Local/Google/Chrome/User Data\Default\old_GPUCache_000
[0513/155639.710:ERROR:disk_cache.cc(184)] Unable to create cache
[0513/155639.710:ERROR:shader_disk_cache.cc(606)] Shader Cache Creation failed: -2
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 2 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 3 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 4 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 5 time(s)
[0513/155639.725:WARNING:gpu_process_host.cc(1204)] The GPU process has crashed 6 time(s)
[0513/155639.725:ERROR:browser_gpu_channel_host_factory.cc(153)] Failed to launch GPU process.
[0513/155642.754:ERROR:service_worker_storage.cc(1624)] Failed to delete the database: Database IO error

...意味着ChromeDriverChrome进程无法移动缓存文件夹。..\Default\GPUCache../AppData/Local/Google/Chrome/User Data\Default\old_GPUCache_000.


深潜

根据该条 无头:使--disable-gpu标志成为不必要的。 很多文章、文档和指南都推荐使用 --disable-gpu 标榜 libosmesa.so 并不存在。有了合并后的 无头。从osmesa切换到SwiftShader 这个标志在Linux或macOS上已不再需要。随着合并后的 始终使用SwiftShader来处理无头Chrome浏览器。 这个标志在Windows上也是不必要的。


解决办法

作为解决方案,你需要删除以下参数。

  • --disable-gpu
  • --disable-software-rasterizer

你可以在以下文章中找到一些相关的讨论。

此外,当试图访问一个特定的 浏览器简介 不提上面 User Data 目录中,你需要更深入一步,并提到了 资料目录../User Data/Profile 2 如下。

options.add_argument("--user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data/Profile 2")

你可以在以下几个相关讨论中找到。

© www.soinside.com 2019 - 2024. All rights reserved.