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: README.md
+19
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,25 @@ with Creator("test.zim").config_indexing(True, "eng") as creator:
127
127
creator.add_metadata(name.title(), value)
128
128
```
129
129
130
+
#### Thread safety
131
+
132
+
> The reading part of the libzim is most of the time thread safe. Searching and creating part are not. [libzim documentation](https://libzim.readthedocs.io/en/latest/usage.html#introduction)
133
+
134
+
`python-libzim` disables the [GIL](https://wiki.python.org/moin/GlobalInterpreterLock) on most of C++ libzim calls. You **must prevent concurrent access** yourself. This is easily done by wrapping all creator calls with a [`threading.Lock()`](https://docs.python.org/3/library/threading.html#lock-objects)
135
+
136
+
```py
137
+
lock = threading.Lock()
138
+
creator = Creator("test.zim")
139
+
140
+
# Thread #1
141
+
with lock:
142
+
creator.add_item(item1)
143
+
144
+
# Thread #2
145
+
with lock:
146
+
creator.add_item(item2)
147
+
```
148
+
130
149
## Building
131
150
132
151
`libzim` package building offers different behaviors via environment variables
0 commit comments