testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

fix(core): Stop container when signals captured

Open lamcw opened this issue 1 year ago • 1 comments

The current atexit hook that stops (and optionally remove) containers in the Docker daemon would not work because of limitations of the atexit module: the handlers are not executed if the Python interpreter is

killed by a signal not handled by Python, when a Python fatal internal error is detected, or when os._exit() is called. https://docs.python.org/3/library/atexit.html

To handle shutdowns of containers completely (for e.g. when the tests are terminated via SIGINT / SIGTERM), we'd need to register signal handlers for them as well.

This kind of acts as an interim solution while #314 is being implemented.

lamcw avatar Mar 15 '24 00:03 lamcw

This issue will be resolved when https://github.com/testcontainers/testcontainers-python/pull/314 lands, which removes the atexit hook completely and removes the dependency on GC to cleanup danglings containers

santi avatar Mar 15 '24 12:03 santi

going to close since reaper v1 has landed, and even reaper v2 (only difference being auto_remove=True (aka docker run --rm) so the instances dont hang out and haunt your system :ghost:)

if any other issues with stopping containers or anything else, just give a shout! @lamcw

alexanderankin avatar Mar 24 '24 18:03 alexanderankin