Skip to content

Commit

Permalink
refactor(subp): Use subprocess.DEVNULL (#4555)
Browse files Browse the repository at this point in the history
Added in Python 3.3, we can safely use this Python feature.
  • Loading branch information
holmanb committed Dec 5, 2023
1 parent 9af8a4a commit 3924113
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions cloudinit/subp.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ def subp(
if rcs is None:
rcs = [0]

devnull_fp = None

if update_env:
if env is None:
env = os.environ
Expand Down Expand Up @@ -240,8 +238,7 @@ def subp(
if data is None:
# using devnull assures any reads get null, rather
# than possibly waiting on input.
devnull_fp = open(os.devnull)
stdin = devnull_fp
stdin = subprocess.DEVNULL
else:
stdin = subprocess.PIPE
if not isinstance(data, bytes):
Expand Down Expand Up @@ -278,9 +275,6 @@ def subp(
stdout="-" if decode else b"-",
stderr="-" if decode else b"-",
) from e
finally:
if devnull_fp:
devnull_fp.close()
if decode:
def ldecode(data, m="utf-8"):
return data.decode(m, decode) if isinstance(data, bytes) else data
Expand Down

0 comments on commit 3924113

Please sign in to comment.