plan291037 commited on
Commit
32b37b7
·
verified ·
1 Parent(s): bf32dca

Update app/lens_images_core.py

Browse files
Files changed (1) hide show
  1. app/lens_images_core.py +19 -0
app/lens_images_core.py CHANGED
@@ -30,6 +30,25 @@ _COMMON_CHROME_PATHS = [
30
  r"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
31
  ]
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  def _find_chrome_binary() -> str | None:
34
  env = os.getenv("CHROME_BINARY")
35
  if env and shutil.which(env):
 
30
  r"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
31
  ]
32
 
33
+ _PROFILE_DIRS = []
34
+
35
+ def _mk_profile_dir() -> str:
36
+ base = os.getenv("CHROME_PROFILE_BASE", tempfile.gettempdir())
37
+ # ผูกกับ PID + thread + UUID เพื่อไม่ชนกัน
38
+ p = os.path.join(base, f"chrome-profile-{os.getpid()}-{threading.get_ident()}-{uuid.uuid4().hex}")
39
+ os.makedirs(p, exist_ok=True)
40
+ _PROFILE_DIRS.append(p)
41
+ return p
42
+
43
+ def _cleanup_profiles():
44
+ for p in _PROFILE_DIRS:
45
+ try:
46
+ shutil.rmtree(p, ignore_errors=True)
47
+ except Exception:
48
+ pass
49
+
50
+ atexit.register(_cleanup_profiles)
51
+
52
  def _find_chrome_binary() -> str | None:
53
  env = os.getenv("CHROME_BINARY")
54
  if env and shutil.which(env):