Commit e99bc84f authored by Per Cederqvist's avatar Per Cederqvist

Detect the running wav2mp3d daemon faster if we need to spawn it.

Also, raise InternalError if the daemon fails to start quickly enough.
parent 36ca69f8
......@@ -48,6 +48,10 @@ class MethodNotAllowed(Response):
def __init__(self, allowed):
super().__init__("405 Method Not Allowed", [('Allow', allowed)])
class InternalError(Response):
def __init__(self, reason):
super().__init__("500 " + reason, [])
class MovedPermanently(Response):
def __init__(self, location):
super().__init__("301 Moved Permanently", [("Location", location)])
......@@ -106,9 +110,15 @@ def get_daemon_connection():
os.path.join(os.path.dirname(__file__),
"wav2mp3d.py"),
"wav2mp3d.py")
time.sleep(1.0)
c = multiprocessing.connection.Client(mp3wavcfg.socketpath, 'AF_UNIX')
return c
for i in range(200):
time.sleep(0.05)
try:
return multiprocessing.connection.Client(mp3wavcfg.socketpath,
'AF_UNIX')
except (FileNotFoundError, ConnectionRefusedError):
pass
raise InternalError("failed to start wav2mp3d")
def convert(environ, start_response, ph):
if len(ph.op_args()) > 0:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment