Skip to content

Commit 0bd4301

Browse files
docs: Update thread_safe description for read-only behavior
Updated documentation to reflect that thread_safe is read-only after initialization and can only be set via DJ_THREAD_SAFE environment variable or datajoint.json config file, not programmatically. Removed references to "one-way lock" pattern which is no longer accurate. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5331fe8 commit 0bd4301

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

docs/design/thread-safe-mode.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ In thread-safe mode, `dj.config` access is blocked except for `thread_safe` itse
3838

3939
| Setting | `thread_safe=False` | `thread_safe=True` |
4040
|---------|---------------------|-------------------|
41-
| `thread_safe` | Read/write | Read-only (one-way lock) |
41+
| `thread_safe` | Read-only (set via env var or config file only) | Read-only |
4242
| All other settings | Read/write | Raises `ThreadSafetyError` |
4343

4444
### Connection-Scoped Settings (`conn.config`)
@@ -518,9 +518,10 @@ dj.conn()
518518
ThreadSafetyError: dj.conn() is disabled in thread-safe mode.
519519
Use Connection.from_config() with explicit configuration.
520520

521-
# Disabling thread-safe mode
522-
dj.config.thread_safe = False
523-
ThreadSafetyError: Cannot disable thread-safe mode once enabled.
521+
# Setting thread-safe mode programmatically
522+
dj.config.thread_safe = True
523+
ThreadSafetyError: thread_safe cannot be set programmatically.
524+
Set DJ_THREAD_SAFE=true in environment or datajoint.json.
524525

525526
# Schema without connection
526527
dj.Schema("my_schema")
@@ -535,9 +536,9 @@ Use Schema('name', connection=conn).
535536
### Unit Tests
536537

537538
1. **Global config in thread-safe mode**
538-
- Verify only `thread_safe` is accessible
539+
- Verify only `thread_safe` is accessible (read-only)
539540
- Verify all other settings raise ThreadSafetyError (read and write)
540-
- Verify one-way lock behavior
541+
- Verify thread_safe cannot be set programmatically (only via env var or config file)
541542

542543
2. **Connection.from_config()**
543544
- Verify all parameters are accepted

src/datajoint/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ class Config(BaseSettings):
344344
default=False,
345345
validation_alias="DJ_THREAD_SAFE",
346346
description="Thread-safe mode. When True, global config access is blocked. "
347-
"Once enabled, cannot be disabled. Use Connection.from_config() instead.",
347+
"Read-only after initialization: set via DJ_THREAD_SAFE env var or datajoint.json. "
348+
"Use Connection.from_config() for thread-safe connections.",
348349
)
349350
filepath_checksum_size_limit: int | None = None
350351

0 commit comments

Comments
 (0)