in project/alcatraz/alcatraz/clusters/local.py [0:0]
def _garbage_collect_net_disk(ntwk: Path, docker_client: DockerClient) -> None:
# TODO this leads to
# urllib3 Connection pool is full, discarding connection: localhost. Connection pool size: 10 error
# fixing this with an environment variable temporarily
if os.environ.get("ALCATRAZ_SKIP_GC_DISK"):
return
# if we can aquire a lock, kill the docker resources
should_remove_file = False
try:
with UnixFileLock(ntwk, timeout=0):
should_remove_file = True
logger.info(f"[garbage-collector] Removing {ntwk.name} lock's resources")
try:
net = docker_client.networks.get("tinydockernet-" + ntwk.name.split(".lock")[0])
net.reload()
for container in net.containers:
container.remove(force=True)
net.remove()
except docker.errors.NotFound:
logger.info(f"[garbage-collector] Network {ntwk.name} not found")
pass
except LockTimeout:
pass
if should_remove_file:
ntwk.unlink(missing_ok=True)