Gracefull shutdown
This commit is contained in:
parent
00920856cc
commit
f4a291b2c0
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -12,6 +13,9 @@ class Advertiser(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
time.sleep(0.4)
|
time.sleep(0.4)
|
||||||
|
if shared.shutting_down:
|
||||||
|
logging.debug('Shutting down Advertiser')
|
||||||
|
break
|
||||||
self._advertise_vectors()
|
self._advertise_vectors()
|
||||||
self._advertise_addresses()
|
self._advertise_addresses()
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ class Listener(threading.Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
|
if shared.shutting_down:
|
||||||
|
logging.debug('Shutting down Listener')
|
||||||
|
break
|
||||||
try:
|
try:
|
||||||
conn, addr = self.s.accept()
|
conn, addr = self.s.accept()
|
||||||
logging.info('Incoming connection from: {}:{}'.format(addr[0], addr[1]))
|
logging.info('Incoming connection from: {}:{}'.format(addr[0], addr[1]))
|
||||||
|
|
|
@ -3,6 +3,7 @@ import csv
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
|
import signal
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from advertiser import Advertiser
|
from advertiser import Advertiser
|
||||||
|
@ -11,7 +12,13 @@ from listener import Listener
|
||||||
import shared
|
import shared
|
||||||
|
|
||||||
|
|
||||||
|
def interrupt_handler(s, f):
|
||||||
|
logging.info('Gracefully shutting down MiNode')
|
||||||
|
shared.shutting_down = True
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
signal.signal(signal.SIGINT, interrupt_handler)
|
||||||
logging.basicConfig(level=shared.log_level, format='[%(asctime)s] [%(levelname)s] %(message)s')
|
logging.basicConfig(level=shared.log_level, format='[%(asctime)s] [%(levelname)s] %(message)s')
|
||||||
logging.info('Starting MiNode')
|
logging.info('Starting MiNode')
|
||||||
if not os.path.exists(shared.data_directory):
|
if not os.path.exists(shared.data_directory):
|
||||||
|
|
|
@ -38,7 +38,10 @@ class Manager(threading.Thread):
|
||||||
self.last_pickled_nodes = now
|
self.last_pickled_nodes = now
|
||||||
|
|
||||||
if shared.shutting_down:
|
if shared.shutting_down:
|
||||||
|
logging.debug('Shutting down connections')
|
||||||
self.shutdown_connections()
|
self.shutdown_connections()
|
||||||
|
logging.debug('Shutting down Manager')
|
||||||
|
break
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clean_objects():
|
def clean_objects():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user