-
Notifications
You must be signed in to change notification settings - Fork 375
feat(core): Add run_containers function in utils.py to run several containers#896
feat(core): Add run_containers function in utils.py to run several containers #896surister wants to merge 1 commit into
run_containers function in utils.py to run several containers #896Conversation
...containers at the same time
alexanderankin
commented
Oct 7, 2025
if we add this can we name it consistently with any one of the other implementations, thanks
if we add this can we name it consistently with any one of the other implementations, thanks
Hm, could you like any of the other implementations? Can't find them @alexanderankin
rhoban13
commented
Oct 13, 2025
I'm admittedly not sure this should be part of the library, when the caller can achieve the same result explicitly with the same amount of code.
with run_containers(
PostgresContainer(network=network),
PostgresContainer(image='postgres:16', network=network),
) as containers:
c1, c2 = containers
Becomes
with contextlib.ExitStack() as stack:
c1, c2 = stack.enter_context(container) for container in (
PostgresContainer(network=network),
PostgresContainer(image='postgres:16', network=network)
)
alexanderankin
commented
Oct 15, 2025
via email
alexanderankin
commented
Oct 15, 2025
via email
rhoban13
commented
Oct 15, 2025
Ahhhh, I see what you're looking to achieve. I could definitely see the parallel container startup being a really useful feature. In it's current form, that's not what this PR proposes.
I suspect such an implementation and would warrant some discussion on which of python's plethora of ways to achieve parallelism makes most sense here.
Uh oh!
There was an error while loading. Please reload this page.
This utils method runs containers on the same context manager. This ensures that the passed containers are run in order and cleaned up.
The main use case is to be able to run code after all containers have started. I need this to create CrateDB clusters.
Practical example: run containers inside a network and clean up the network (network can only be cleaned up after all containers using it are stopped)