Check if thread exits

This commit is contained in:
Thiago Kenji Okada 2016-10-26 21:21:09 -02:00
parent d311a53284
commit 006fd14bb8

View File

@ -2,7 +2,7 @@ import os
import re import re
import signal import signal
import threading import threading
from subprocess import Popen, PIPE, CalledProcessError from subprocess import Popen, PIPE
from i3pystatus import IntervalModule, formatp from i3pystatus import IntervalModule, formatp
@ -100,9 +100,7 @@ class RedshiftController(threading.Thread):
self.parse_output(line) self.parse_output(line)
self._p.stdout.close() self._p.stdout.close()
return_code = self._p.wait() self._p.wait(10)
if return_code != 0:
raise CalledProcessError("redshift exited with {} return code".format(return_code))
class Redshift(IntervalModule): class Redshift(IntervalModule):
@ -162,8 +160,8 @@ class Redshift(IntervalModule):
self.inhibit = True self.inhibit = True
def run(self): def run(self):
self.update_values() if self._controller.is_alive():
try: self.update_values()
fdict = { fdict = {
"inhibit": self.format_inhibit[int(self.inhibit)], "inhibit": self.format_inhibit[int(self.inhibit)],
"period": self.period, "period": self.period,
@ -171,12 +169,13 @@ class Redshift(IntervalModule):
"latitude": self.latitude, "latitude": self.latitude,
"longitude": self.longitude, "longitude": self.longitude,
} }
output = formatp(self.format, **fdict)
color = self.color color = self.color
except CalledProcessError as err: else:
fdict = {"error": err} output = "redshift exited unexpectedly"
color = self.error_color color = self.error_color
self.output = { self.output = {
"full_text": formatp(self.format, **fdict), "full_text": output,
"color": color, "color": color,
} }