Skip to content

Commit

Permalink
allow clean shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneu committed Feb 3, 2019
1 parent d68dc28 commit f2d1ef7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
13 changes: 13 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from honeycast.certificate import Key, Certificate
from honeycast.config import config
from honeycast.discovery import Discovery
from honeycast.log import logger
from honeycast.web import httpd
from multiprocessing import Process
from optparse import OptionParser
from uuid import uuid4
import time

if __name__ == "__main__":
parser = OptionParser()
Expand Down Expand Up @@ -68,5 +70,16 @@
processes.append(server_process)

for process in processes:
process.daemon = True
process.start()

while True:
try:
time.sleep(24 * 60 * 60)
except KeyboardInterrupt:
logger.info("shutting down")

for process in processes:
process.terminate()

exit(0)
17 changes: 10 additions & 7 deletions honeycast/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ def get_client(self):

def run(self):
while True:
client = self.get_client()
while True:
try:
client.receive_and_reply_once()
except CastException as ex:
logger.warning("exception in cast client: %s", ex.message)
break
try:
client = self.get_client()
while True:
try:
client.receive_and_reply_once()
except CastException as ex:
logger.warning("exception in cast client: %s", ex.message)
break
except KeyboardInterrupt:
break

class CastClient:
def __init__(self, socket):
Expand Down
7 changes: 5 additions & 2 deletions honeycast/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ def run(self):

logger.info("starting discovery")

self._zeroconf = Zeroconf()
self._zeroconf.register_service(self._service)
try:
self._zeroconf = Zeroconf()
self._zeroconf.register_service(self._service)
except KeyboardInterrupt:
pass

def stop(self):
if self._zeroconf is None:
Expand Down

0 comments on commit f2d1ef7

Please sign in to comment.