Fix ResourceWarning in moto.settings.is_docker(). (#5060)

This commit is contained in:
Nick Pope 2022-04-25 21:17:49 +01:00 committed by GitHub
parent afe4b3ace9
commit d12254309d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import json
import os
import pathlib
from functools import lru_cache
@ -85,11 +86,11 @@ def test_server_mode_endpoint():
def is_docker():
path = "/proc/self/cgroup"
path = pathlib.Path("/proc/self/cgroup")
return (
os.path.exists("/.dockerenv")
or os.path.isfile(path)
and any("docker" in line for line in open(path))
or path.is_file()
and any("docker" in line for line in path.read_text())
)