Added "--shutdown-timeout" option to PIO Home Server

This commit is contained in:
Ivan Kravets
2019-11-01 14:40:03 +02:00
parent cd3d638337
commit da928efb43
4 changed files with 19 additions and 7 deletions

View File

@@ -76,23 +76,25 @@ class JSONRPCServerProtocol(WebSocketServerProtocol):
class JSONRPCServerFactory(WebSocketServerFactory):
SHUTDOWN_TIMEOUT = 3600 # in seconds
protocol = JSONRPCServerProtocol
connection_nums = 0
shutdown_timer = 0
def __init__(self):
def __init__(self, shutdown_timeout=0):
super(JSONRPCServerFactory, self).__init__()
self.shutdown_timeout = shutdown_timeout
self.dispatcher = jsonrpc.Dispatcher()
def shutdownByTimeout(self):
if self.shutdown_timeout < 1:
return
def _auto_shutdown_server():
click.echo("Automatically shutdown server on timeout")
reactor.stop()
self.shutdown_timer = reactor.callLater(
self.SHUTDOWN_TIMEOUT, _auto_shutdown_server
self.shutdown_timeout, _auto_shutdown_server
)
def addHandler(self, handler, namespace):