Skip to content

Commit b1671ed

Browse files
armui.py code cleanup
Properly handle file checks, removing resource leak, closing file once read.
1 parent 6c82f95 commit b1671ed

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

arm/runui.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ def is_docker():
4444
returns: Boolean
4545
"""
4646
path = '/proc/self/cgroup'
47-
return (
48-
os.path.exists('/.dockerenv') or
49-
os.path.isfile(path) and any('docker' in line for line in open(path))
50-
)
47+
48+
if os.path.exists('/.dockerenv'):
49+
return True
50+
51+
if os.path.isfile(path):
52+
with open(path) as f:
53+
return any('docker' in line for line in f)
54+
55+
return False
5156

5257

5358
def get_host():

0 commit comments

Comments
 (0)