Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix multiprocess semaphore scope stale
Nick Sweeting11b187576eb4
diff --git a/browser_use/utils.py b/browser_use/utils.pyindex ea4f4a76c..59f3f3110 100644--- a/browser_use/utils.py+++ b/browser_use/utils.py@@ -623,7 +623,7 @@ MULTIPROCESS_SEMAPHORE_DIR = Path(tempfile.gettempdir()) / 'browser_use_semaphorMULTIPROCESS_SEMAPHORE_DIR.mkdir(exist_ok=True)# Global multiprocess semaphore registry-MULTIPROCESS_SEMAPHORES: dict[str, portalocker.utils.NamedBoundedSemaphore] = {}+# Multiprocess semaphores are not cached due to internal state issues causing "Already locked" errorsMULTIPROCESS_SEMAPHORE_LOCK = threading.Lock()# Global overload detection state@@ -727,14 +727,13 @@ def retry(# Use multiprocess semaphoresem_key = base_namewith MULTIPROCESS_SEMAPHORE_LOCK:- if sem_key not in MULTIPROCESS_SEMAPHORES:- # Create a NamedBoundedSemaphore with the given limit- MULTIPROCESS_SEMAPHORES[sem_key] = portalocker.utils.NamedBoundedSemaphore(- maximum=semaphore_limit,- name=sem_key,- directory=str(MULTIPROCESS_SEMAPHORE_DIR),- )- semaphore = MULTIPROCESS_SEMAPHORES[sem_key]+ # Don't cache multiprocess semaphores - they have internal state issues+ # Create a new instance each time to avoid "Already locked" errors+ semaphore = portalocker.utils.NamedBoundedSemaphore(+ maximum=semaphore_limit,+ name=sem_key,+ directory=str(MULTIPROCESS_SEMAPHORE_DIR),+ )else:# Use in-process semaphoreif semaphore_scope == 'global':