mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-21 23:46:50 +00:00
fix(sandbox): prevent memory leak in file operation locks using WeakValueDictionary (#2096)
* fix(sandbox): prevent memory leak in file operation locks using WeakValueDictionary * lint: fix lint issue in sandbox tools security
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import threading
|
||||
import weakref
|
||||
|
||||
from deerflow.sandbox.sandbox import Sandbox
|
||||
|
||||
_FILE_OPERATION_LOCKS: dict[tuple[str, str], threading.Lock] = {}
|
||||
# Use WeakValueDictionary to prevent memory leak in long-running processes.
|
||||
# Locks are automatically removed when no longer referenced by any thread.
|
||||
_LockKey = tuple[str, str]
|
||||
_FILE_OPERATION_LOCKS: weakref.WeakValueDictionary[_LockKey, threading.Lock] = weakref.WeakValueDictionary()
|
||||
_FILE_OPERATION_LOCKS_GUARD = threading.Lock()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user