From 11ffa5115649f80235e2864754bb603b106d7053 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Sun, 15 Nov 2015 10:19:12 -0800 Subject: [PATCH] Fix start/stop buttons on web broken by faster start/stop patch In past versions, startProcess() and stopProcess() would always return a callback. 50d18577af28b6b053c0d446c959b42b5300a0f8 changed this so they may return either a callback or a bool, but the web interface was not updated. --- supervisor/web.py | 80 ++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/supervisor/web.py b/supervisor/web.py index a68f42b97..8a6c8194d 100644 --- a/supervisor/web.py +++ b/supervisor/web.py @@ -336,8 +336,9 @@ def wrong(): if action == 'start': try: - callback = rpcinterface.supervisor.startProcess( - namespec) + bool_or_callback = ( + rpcinterface.supervisor.startProcess(namespec) + ) except RPCError as e: if e.code == Faults.NO_FILE: msg = 'no such file' @@ -357,29 +358,36 @@ def starterr(): starterr.delay = 0.05 return starterr - def startprocess(): - try: - result = callback() - except RPCError as e: - if e.code == Faults.SPAWN_ERROR: - msg = 'spawn error' - elif e.code == Faults.ABNORMAL_TERMINATION: - msg = 'abnormal termination' - else: - msg = 'unexpected rpc fault [%d] %s' % ( - e.code, e.text) - return 'ERROR: Process %s: %s' % (namespec, msg) - - if result is NOT_DONE_YET: - return NOT_DONE_YET - return 'Process %s started' % namespec - startprocess.delay = 0.05 - return startprocess + if callable(bool_or_callback): + def startprocess(): + try: + result = bool_or_callback() + except RPCError as e: + if e.code == Faults.SPAWN_ERROR: + msg = 'spawn error' + elif e.code == Faults.ABNORMAL_TERMINATION: + msg = 'abnormal termination' + else: + msg = 'unexpected rpc fault [%d] %s' % ( + e.code, e.text) + return 'ERROR: Process %s: %s' % (namespec, msg) + + if result is NOT_DONE_YET: + return NOT_DONE_YET + return 'Process %s started' % namespec + startprocess.delay = 0.05 + return startprocess + else: + def startdone(): + return 'Process %s started' % namespec + startdone.delay = 0.05 + return startdone elif action == 'stop': try: - callback = rpcinterface.supervisor.stopProcess( - namespec) + bool_or_callback = ( + rpcinterface.supervisor.stopProcess(namespec) + ) except RPCError as e: def stoperr(): return 'unexpected rpc fault [%d] %s' % ( @@ -387,17 +395,23 @@ def stoperr(): stoperr.delay = 0.05 return stoperr - def stopprocess(): - try: - result = callback() - except RPCError as e: - return 'unexpected rpc fault [%d] %s' % ( - e.code, e.text) - if result is NOT_DONE_YET: - return NOT_DONE_YET - return 'Process %s stopped' % namespec - stopprocess.delay = 0.05 - return stopprocess + if callable(bool_or_callback): + def stopprocess(): + try: + result = bool_or_callback() + except RPCError as e: + return 'unexpected rpc fault [%d] %s' % ( + e.code, e.text) + if result is NOT_DONE_YET: + return NOT_DONE_YET + return 'Process %s stopped' % namespec + stopprocess.delay = 0.05 + return stopprocess + else: + def stopdone(): + return 'Process %s stopped' % namespec + stopdone.delay = 0.05 + return stopdone elif action == 'restart': callback = rpcinterface.system.multicall(