|
21 | 21 |
|
22 | 22 |
|
23 | 23 | def remove_containers_by_label(client: docker.DockerClient, run_id: str) -> None: |
24 | | - with contextlib.suppress(NotFound): |
| 24 | + with contextlib.suppress(Exception): |
25 | 25 | for c in client.containers.list(all=True, filters={"label": f"datasmith.run={run_id}"}): |
26 | 26 | c.remove(force=True) |
27 | 27 |
|
28 | 28 |
|
29 | 29 | def remove_images_by_label(client: docker.DockerClient, run_id: str) -> None: |
30 | 30 | # List is cheap and does not contend. Remove by ID avoids tag races. |
31 | | - imgs = client.images.list(filters={"label": f"datasmith.run={run_id}"}) |
32 | | - for img in imgs: |
33 | | - try: |
34 | | - client.images.remove(img.id, force=True, noprune=False) |
35 | | - except (ImageNotFound, NotFound): |
36 | | - pass |
37 | | - except APIError as e: |
38 | | - # 409 conflict: still in use by a live container; skip |
39 | | - if getattr(e, "status_code", None) != 409: |
40 | | - # Optional: log at DEBUG |
| 31 | + with contextlib.suppress(Exception): |
| 32 | + imgs = client.images.list(filters={"label": f"datasmith.run={run_id}"}) |
| 33 | + for img in imgs: |
| 34 | + try: |
| 35 | + client.images.remove(img.id, force=True, noprune=False) |
| 36 | + except (ImageNotFound, NotFound): |
41 | 37 | pass |
| 38 | + except APIError as e: |
| 39 | + # 409 conflict: still in use by a live container; skip |
| 40 | + if getattr(e, "status_code", None) != 409: |
| 41 | + # Optional: log at DEBUG |
| 42 | + pass |
42 | 43 |
|
43 | 44 |
|
44 | 45 | def gen_run_labels(t: Task, runid: str) -> dict[str, str]: |
|
0 commit comments