GPU进程在无头模式下使用ChromeDriver和Chrome以及disablegpu和userdatadir参数,导致x时间错误崩溃

2024-09-29 22:22:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用selenium打开一个网站。具体而言:

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")

当然,不是所有的参数都同时出现,而是在不同的时间使用不同的块。尽管这里需要注意的是,当我使用参数--no sandbox时,错误变为

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)

它是有效的。但与无头模式相比,它的速度非常慢

我不能用速度来交易。我怎样才能解决这个问题


Tags: httpscomaddmodelsstorageargumentprocesscamera
1条回答
网友
1楼 · 发布于 2024-09-29 22:22:06

此错误消息

[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

…表示ChromeDriver/Chrome进程无法将缓存文件夹..\Default\GPUCache移动到../AppData/Local/Google/Chrome/User Data\Default\old_GPUCache_000


深潜

根据文章Headless: make disable-gpu flag unnecessary,许多文章、文档和指南建议使用 disable-gpu标志,因为libosmesa.so不存在。随着mergeheadless: Switch from osmesa to SwiftShader的可用性,Linux或macOS上不再需要此标志。随着mergeAlways use SwiftShader for headless Chrome的可用性向前推进,即使在Windows上,这个标志也是不必要的


解决方案

作为解决方案,您需要删除以下参数:

  • disable-gpu
  • disable-software-rasterizer

您可以在以下内容中找到一些相关讨论:

此外,当尝试访问特定的Chrome配置文件而不是提及顶部User Data目录时,您需要更深入一步,并提及配置文件目录例如../User Data/Profile 2,如下所示:

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

您可以在以下内容中找到一些相关讨论:

相关问题 更多 >

    热门问题