You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Implement thread-safe mode with Instance class
- Add Instance class that encapsulates config + connection
- Add ThreadSafetyError exception for global state access
- Add _ConfigProxy to delegate dj.config to global config
- Add _get_singleton_connection for lazy connection creation
- Update dj.conn(), dj.Schema(), dj.FreeTable() to use singleton
- Connection now stores _config reference for instance isolation
- Add DJ_THREAD_SAFE environment variable support
- Add comprehensive tests for thread-safe mode
When DJ_THREAD_SAFE=true:
- dj.config raises ThreadSafetyError
- dj.conn() raises ThreadSafetyError
- dj.Schema() raises ThreadSafetyError (without explicit connection)
- dj.FreeTable() raises ThreadSafetyError (without explicit connection)
- dj.Instance() always works for isolated contexts
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/design/thread-safe-mode.md
+70-49Lines changed: 70 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,30 +6,34 @@ DataJoint uses global state (`dj.config`, `dj.conn()`) that is not thread-safe.
6
6
7
7
## Solution
8
8
9
-
Introduce **Instance** objects that encapsulate config and connection. The `dj` module provides access to a lazily-loaded singleton instance. New isolated instances are created with `dj.Instance()`.
9
+
Introduce **Instance** objects that encapsulate config and connection. The `dj` module provides a global config that can be modified before connecting, and a lazily-loaded singleton connection. New isolated instances are created with `dj.Instance()`.
10
10
11
11
## API
12
12
13
-
### Legacy API (singleton instance)
13
+
### Legacy API (global config + singleton connection)
0 commit comments