CC-5227 - Sometimes Liquidsoap telnet is unresponsive which causes all Pypo threads to block
-initial commit
This commit is contained in:
parent
3391aa90c5
commit
f164cf0ad4
5 changed files with 70 additions and 25 deletions
38
python_apps/pypo/timeout.py
Normal file
38
python_apps/pypo/timeout.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import threading
|
||||
import logging
|
||||
|
||||
def __timeout(func, timeout_duration, default, args, kwargs):
|
||||
|
||||
class InterruptableThread(threading.Thread):
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
self.result = default
|
||||
def run(self):
|
||||
self.result = func(*args, **kwargs)
|
||||
|
||||
first_attempt = True
|
||||
|
||||
while True:
|
||||
it = InterruptableThread()
|
||||
it.start()
|
||||
it.join(timeout_duration)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
if it.isAlive():
|
||||
"""Restart Liquidsoap and try the command one more time. If it
|
||||
fails again then there is something critically wrong..."""
|
||||
if first_attempt:
|
||||
#restart liquidsoap
|
||||
pass
|
||||
else:
|
||||
raise Exception("Thread did not terminate")
|
||||
else:
|
||||
return it.result
|
||||
|
||||
first_attempt = False
|
||||
|
||||
def ls_timeout(f, timeout=4, default=None):
|
||||
def new_f(*args, **kwargs):
|
||||
return __timeout(f, timeout, default, args, kwargs)
|
||||
return new_f
|
Loading…
Add table
Add a link
Reference in a new issue