Skip to content

Commit a18295b

Browse files
committed
Add some docs about thread safety
1 parent 0c88f26 commit a18295b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ The module will return an ``InvalidDatabaseError`` if the database is corrupt
9494
or otherwise invalid. A ``ValueError`` will be thrown if you look up an
9595
invalid IP address or an IPv6 address in an IPv4 database.
9696

97+
Thread Safety
98+
-------------
99+
100+
Both the C extension and pure Python implementations are safe for concurrent
101+
reads and support Python 3.13+ free-threading. The C extension provides
102+
free-threading support on platforms with pthread support (such as Linux and
103+
macOS) and Windows. On other platforms, the extension will use GIL-based
104+
protection. Calling ``close()`` while reads are in progress may cause
105+
exceptions in those threads.
106+
97107
Requirements
98108
------------
99109

maxminddb/reader.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,10 @@ def _load_buffer(
288288
return filename
289289

290290
def close(self) -> None:
291-
"""Close the MaxMind DB file and returns the resources to the system."""
291+
"""Close the MaxMind DB file and returns the resources to the system.
292+
293+
Calling this method while reads are in progress may cause exceptions.
294+
"""
292295
with contextlib.suppress(AttributeError):
293296
self._buffer.close() # type: ignore[union-attr]
294297

0 commit comments

Comments
 (0)