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
Copy file name to clipboardExpand all lines: docs/design/thread-safe-mode.md
+95-71Lines changed: 95 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,11 @@ DataJoint uses global state (`dj.config`, `dj.conn()`) that is not thread-safe.
6
6
7
7
## Solution
8
8
9
-
Introduce **context** objects that encapsulate config and connection. The `dj` module provides the singleton (legacy) context. New isolated contexts are created with `dj.new()`.
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()`.
10
10
11
11
## API
12
12
13
-
### Legacy API (singleton context)
13
+
### Legacy API (singleton instance)
14
14
15
15
```python
16
16
import datajoint as dj
@@ -24,36 +24,38 @@ class Mouse(dj.Manual):
24
24
definition ="..."
25
25
```
26
26
27
-
### New API (isolated context)
27
+
Internally, `dj.config`, `dj.conn()`, and `dj.Schema()` delegate to a lazily-loaded singleton instance.
28
+
29
+
### New API (isolated instance)
28
30
29
31
```python
30
32
import datajoint as dj
31
33
32
-
ctx= dj.new(
34
+
inst= dj.instance(
33
35
host="localhost",
34
36
user="user",
35
37
password="password",
36
38
)
37
-
ctx.config.safemode =False
38
-
schema =ctx.Schema("my_schema")
39
+
inst.config.safemode =False
40
+
schema =inst.Schema("my_schema")
39
41
40
42
@schema
41
43
classMouse(dj.Manual):
42
44
definition ="..."
43
45
```
44
46
45
-
### Context structure
47
+
### Instance structure
46
48
47
-
Each context exposes only:
48
-
-`ctx.config` - Config instance (copy of `dj.config` at creation)
49
-
-`ctx.connection` - Connection (created at context construction)
50
-
-`ctx.Schema()` - Schema factory using context's connection
49
+
Each instance has:
50
+
-`inst.config` - Config (created fresh at instance creation)
51
+
-`inst.connection` - Connection (created at instance creation)
52
+
-`inst.Schema()` - Schema factory using instance's connection
0 commit comments