Add GPU-aware launch and testing docs
This commit is contained in:
@@ -7,6 +7,7 @@ import logging
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -25,6 +26,49 @@ DATE_FORMATS = (
|
||||
"%B %d, %Y",
|
||||
)
|
||||
|
||||
GPU_ACCEL_ENV = "ENABLE_GPU"
|
||||
|
||||
|
||||
def parse_env_flag(value, default=False):
|
||||
if value is None:
|
||||
return default
|
||||
return str(value).strip().lower() in ("1", "true", "yes", "on")
|
||||
|
||||
|
||||
def detect_gpu_available():
|
||||
env_value = os.getenv(GPU_ACCEL_ENV)
|
||||
if env_value is not None:
|
||||
return parse_env_flag(env_value, default=False)
|
||||
|
||||
nvidia_visible = os.getenv("NVIDIA_VISIBLE_DEVICES")
|
||||
if nvidia_visible and nvidia_visible.lower() not in ("none", "void", "off"):
|
||||
return True
|
||||
|
||||
if os.path.exists("/dev/nvidia0"):
|
||||
return True
|
||||
|
||||
if os.path.exists("/dev/dri/renderD128") or os.path.exists("/dev/dri/card0"):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def chromium_launch_args():
|
||||
if not detect_gpu_available():
|
||||
return []
|
||||
|
||||
if os.name == "nt":
|
||||
return ["--enable-gpu"]
|
||||
|
||||
return [
|
||||
"--enable-gpu",
|
||||
"--ignore-gpu-blocklist",
|
||||
"--disable-software-rasterizer",
|
||||
"--use-gl=egl",
|
||||
"--enable-zero-copy",
|
||||
"--enable-gpu-rasterization",
|
||||
]
|
||||
|
||||
|
||||
def parse_date(value):
|
||||
for fmt in DATE_FORMATS:
|
||||
@@ -396,7 +440,12 @@ def scrape_yahoo_options(symbol, expiration=None, strike_limit=25):
|
||||
fallback_to_base = False
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
launch_args = chromium_launch_args()
|
||||
if launch_args:
|
||||
app.logger.info("GPU acceleration enabled")
|
||||
else:
|
||||
app.logger.info("GPU acceleration disabled")
|
||||
browser = p.chromium.launch(headless=True, args=launch_args)
|
||||
page = browser.new_page()
|
||||
page.set_extra_http_headers(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user