Skip to content

Commit

Permalink
Add thread safety note on README
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaudin committed Feb 12, 2024
1 parent 3b8645b commit 7fe5fea
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,25 @@ with Creator("test.zim").config_indexing(True, "eng") as creator:
creator.add_metadata(name.title(), value)
```

#### Thread safety

> 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)
`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)

```py
lock = threading.Lock()
creator = Creator("test.zim")

# Thread #1
with lock:
creator.add_item(item1)

# Thread #2
with lock:
creator.add_item(item2)
```

## Building

`libzim` package building offers different behaviors via environment variables
Expand Down

0 comments on commit 7fe5fea

Please sign in to comment.