Skip to content

Commit 33fae08

Browse files
fix(core): close Reaper socket at interpreter exit to prevent ResourceWarning
The Ryuk keep-alive socket stored in `Reaper._socket` was never explicitly closed, so CPython's GC finalized it during interpreter shutdown and emitted a ResourceWarning ("unclosed <socket.socket ...>") that is impossible to suppress via warnings filters because it fires after pytest exits. Registering `Reaper.delete_instance` with `atexit` ensures the socket is closed cleanly before the GC sweep, eliminating the warning without changing the socket's lifetime during the test session. Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
1 parent 6deaf3b commit 33fae08

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎core/testcontainers/core/container.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import atexit
12
import contextlib
23
import io
34
import pathlib
@@ -476,5 +477,6 @@ def _create_instance(cls) -> "Reaper":
476477
rs.send(f"label={LABEL_SESSION_ID}={SESSION_ID}\r\n".encode())
477478

478479
Reaper._instance = Reaper()
480+
atexit.register(Reaper.delete_instance)
479481

480482
return Reaper._instance

0 commit comments

Comments
 (0)