coding style: Can use the Popen context manager to close and wait
This commit is contained in:
parent
ce224275e9
commit
ff1f2c8760
1 changed files with 3 additions and 6 deletions
|
|
@ -1112,14 +1112,11 @@ def manage_cache(root_path):
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def print_to_pager(pager_command=["less", "-RFEX"]):
|
def print_to_pager(pager_command=["less", "-RFEX"]):
|
||||||
try:
|
try:
|
||||||
pager_process = subprocess.Popen(pager_command, stdin=subprocess.PIPE, text=True)
|
with subprocess.Popen(pager_command, stdin=subprocess.PIPE, text=True) as pager_process:
|
||||||
|
with contextlib.redirect_stdout(pager_process.stdin):
|
||||||
|
yield
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
yield
|
yield
|
||||||
else:
|
|
||||||
with contextlib.redirect_stdout(pager_process.stdin):
|
|
||||||
yield
|
|
||||||
pager_process.stdin.close()
|
|
||||||
pager_process.wait()
|
|
||||||
|
|
||||||
|
|
||||||
def print_tool_info():
|
def print_tool_info():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue