Do not wait for update lock, exit
This commit is contained in:
parent
63a50ad200
commit
ca2f0cc873
|
@ -23,9 +23,9 @@ class ThreadedSegment(object):
|
||||||
self.did_set_interval = False
|
self.did_set_interval = False
|
||||||
self.thread = None
|
self.thread = None
|
||||||
|
|
||||||
def __call__(self, update_first=True, **kwargs):
|
def __call__(self, pl, update_first=True, **kwargs):
|
||||||
if self.run_once:
|
if self.run_once:
|
||||||
self.pl = kwargs['pl']
|
self.pl = pl
|
||||||
self.set_state(**kwargs)
|
self.set_state(**kwargs)
|
||||||
self.update()
|
self.update()
|
||||||
elif not self.is_alive():
|
elif not self.is_alive():
|
||||||
|
@ -39,7 +39,7 @@ class ThreadedSegment(object):
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
with self.write_lock:
|
with self.write_lock:
|
||||||
return self.render(update_first=update_first, **kwargs)
|
return self.render(update_first=update_first, pl=pl, **kwargs)
|
||||||
|
|
||||||
def is_alive(self):
|
def is_alive(self):
|
||||||
return self.thread and self.thread.is_alive()
|
return self.thread and self.thread.is_alive()
|
||||||
|
@ -56,11 +56,19 @@ class ThreadedSegment(object):
|
||||||
while self.keep_going:
|
while self.keep_going:
|
||||||
start_time = monotonic()
|
start_time = monotonic()
|
||||||
|
|
||||||
with self.update_lock:
|
try:
|
||||||
try:
|
if self.update_lock.acquire(False):
|
||||||
self.update()
|
try:
|
||||||
except Exception as e:
|
self.update()
|
||||||
self.error('Exception while updating: {0}', str(e))
|
except Exception as e:
|
||||||
|
self.error('Exception while updating: {0}', str(e))
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
finally:
|
||||||
|
# Release lock in any case. If it is not locked in this thread,
|
||||||
|
# it was done in main thread in .shutdown method, and the lock
|
||||||
|
# will never be released.
|
||||||
|
self.update_lock.release()
|
||||||
|
|
||||||
self.sleep(monotonic() - start_time)
|
self.sleep(monotonic() - start_time)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue