Use context manager in Popen
This commit is contained in:
parent
006fd14bb8
commit
0f9b0a1ac3
@ -32,7 +32,14 @@ class RedshiftController(threading.Thread):
|
|||||||
|
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['LANG'] = env['LANGUAGE'] = env['LC_ALL'] = env['LC_MESSAGES'] = 'C'
|
env['LANG'] = env['LANGUAGE'] = env['LC_ALL'] = env['LC_MESSAGES'] = 'C'
|
||||||
self._p = Popen(cmd, env=env, stdout=PIPE, bufsize=1, universal_newlines=True)
|
|
||||||
|
self._params = {
|
||||||
|
"args": cmd,
|
||||||
|
"env": env,
|
||||||
|
"bufsize": 1,
|
||||||
|
"stdout": PIPE,
|
||||||
|
"universal_newlines": True,
|
||||||
|
}
|
||||||
|
|
||||||
def parse_output(self, line):
|
def parse_output(self, line):
|
||||||
"""Convert output to key value pairs"""
|
"""Convert output to key value pairs"""
|
||||||
@ -96,11 +103,10 @@ class RedshiftController(threading.Thread):
|
|||||||
self._inhibited = inhibit
|
self._inhibited = inhibit
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
for line in self._p.stdout:
|
with Popen(**self._params) as proc:
|
||||||
self.parse_output(line)
|
for line in proc.stdout:
|
||||||
|
self.parse_output(line)
|
||||||
self._p.stdout.close()
|
proc.wait(10)
|
||||||
self._p.wait(10)
|
|
||||||
|
|
||||||
|
|
||||||
class Redshift(IntervalModule):
|
class Redshift(IntervalModule):
|
||||||
|
Loading…
Reference in New Issue
Block a user