Commit cb955072 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Code simplification: less indentation levels in get_daemon_connection().

By using a simple return statement in the normal case when a wav2mp3d
daemon is already running, the code can be simplified.
parent 73037e91
......@@ -92,25 +92,28 @@ def process_request(environ, start_response):
def get_daemon_connection():
try:
c = multiprocessing.connection.Client(mp3wavcfg.socketpath, 'AF_UNIX')
return multiprocessing.connection.Client(mp3wavcfg.socketpath,
'AF_UNIX')
except FileNotFoundError:
try:
sys.stderr.write("Removing %s\n" % mp3wavcfg.socketpath)
os.remove(mp3wavcfg.socketpath)
sys.stderr.write("Removed %s\n" % mp3wavcfg.socketpath)
except FileNotFoundError:
sys.stderr.write("Failed to remove %s\n" % mp3wavcfg.socketpath)
pass
sys.stderr.write("Spawning wav2mp3d...\n")
pid = os.spawnl(os.P_NOWAIT,
os.path.join(os.path.dirname(__file__),
"wav2mp3d.py"),
"wav2mp3d.py")
sys.stderr.write("Spawned wav2mp3d (pid %d). Waiting one sec.\n" % pid)
time.sleep(1.0)
sys.stderr.write("Connecting to new wav2mp3d.\n")
c = multiprocessing.connection.Client(mp3wavcfg.socketpath, 'AF_UNIX')
sys.stderr.write("Connected to new wav2mp3d.\n")
pass
try:
sys.stderr.write("Removing %s\n" % mp3wavcfg.socketpath)
os.remove(mp3wavcfg.socketpath)
sys.stderr.write("Removed %s\n" % mp3wavcfg.socketpath)
except FileNotFoundError:
sys.stderr.write("Failed to remove %s\n" % mp3wavcfg.socketpath)
pass
sys.stderr.write("Spawning wav2mp3d...\n")
pid = os.spawnl(os.P_NOWAIT,
os.path.join(os.path.dirname(__file__),
"wav2mp3d.py"),
"wav2mp3d.py")
sys.stderr.write("Spawned wav2mp3d (pid %d). Waiting one sec.\n" % pid)
time.sleep(1.0)
sys.stderr.write("Connecting to new wav2mp3d.\n")
c = multiprocessing.connection.Client(mp3wavcfg.socketpath, 'AF_UNIX')
sys.stderr.write("Connected to new wav2mp3d.\n")
return c
def convert(environ, start_response, ph):
......
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