Skip to content

Commit

Permalink
Switched SIGTERM handler to gevent.signal_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 committed May 20, 2020
1 parent 5c617f8 commit 4810247
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/labthings/server/wsgi/gevent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from geventwebsocket.handler import WebSocketHandler
import gevent
import socket
import logging
import signal
import logging
from werkzeug.debug import DebuggedApplication

from zeroconf import IPVersion, ServiceInfo, Zeroconf, get_all_addresses
Expand Down Expand Up @@ -79,17 +79,15 @@ def register_zeroconf(self):
for service in self.service_infos:
self.zeroconf_server.register_service(service)

def stop(self, timeout=1):
def stop(self):
# Unregister zeroconf service
if self.zeroconf_server:
for service in self.service_infos:
self.zeroconf_server.unregister_service(service)
self.zeroconf_server.close()
self.zeroconf_server = None
# Stop WSGI server with timeout
if self.wsgi_server:
self.wsgi_server.stop(timeout=timeout)
self.wsgi_server = None
self.wsgi_server.stop(timeout=5)
# Clear started event
if self.started_event.is_set():
self.started_event.clear()
Expand Down Expand Up @@ -129,7 +127,7 @@ def start(self):
)

# Serve
signal.signal(signal.SIGTERM, self.stop)
gevent.signal_handler(signal.SIGTERM, self.stop)

# Set started event
self.started_event.set()
Expand Down

0 comments on commit 4810247

Please sign in to comment.