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