|
@ -15,7 +15,9 @@ class DbTransfer(object): |
|
|
instance = None |
|
|
instance = None |
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
|
|
|
import threading |
|
|
self.last_get_transfer = {} |
|
|
self.last_get_transfer = {} |
|
|
|
|
|
self.event = threading.Event() |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def get_instance(): |
|
|
def get_instance(): |
|
@ -148,6 +150,15 @@ class DbTransfer(object): |
|
|
logging.info('db stop server at port [%s] reason: port not exist' % (row['port'])) |
|
|
logging.info('db stop server at port [%s] reason: port not exist' % (row['port'])) |
|
|
ServerPool.get_instance().cb_del_server(row['port']) |
|
|
ServerPool.get_instance().cb_del_server(row['port']) |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
def del_servers(): |
|
|
|
|
|
for port in ServerPool.get_instance().tcp_servers_pool.keys(): |
|
|
|
|
|
if ServerPool.get_instance().server_is_run(port) > 0: |
|
|
|
|
|
ServerPool.get_instance().cb_del_server(port) |
|
|
|
|
|
for port in ServerPool.get_instance().tcp_ipv6_servers_pool.keys(): |
|
|
|
|
|
if ServerPool.get_instance().server_is_run(port) > 0: |
|
|
|
|
|
ServerPool.get_instance().cb_del_server(port) |
|
|
|
|
|
|
|
|
@staticmethod |
|
|
@staticmethod |
|
|
def thread_db(): |
|
|
def thread_db(): |
|
|
import socket |
|
|
import socket |
|
@ -155,6 +166,7 @@ class DbTransfer(object): |
|
|
timeout = 60 |
|
|
timeout = 60 |
|
|
socket.setdefaulttimeout(timeout) |
|
|
socket.setdefaulttimeout(timeout) |
|
|
last_rows = [] |
|
|
last_rows = [] |
|
|
|
|
|
try: |
|
|
while True: |
|
|
while True: |
|
|
try: |
|
|
try: |
|
|
DbTransfer.get_instance().push_db_all_user() |
|
|
DbTransfer.get_instance().push_db_all_user() |
|
@ -165,6 +177,14 @@ class DbTransfer(object): |
|
|
trace = traceback.format_exc() |
|
|
trace = traceback.format_exc() |
|
|
logging.error(trace) |
|
|
logging.error(trace) |
|
|
#logging.warn('db thread except:%s' % e) |
|
|
#logging.warn('db thread except:%s' % e) |
|
|
finally: |
|
|
if DbTransfer.get_instance().event.wait(15): |
|
|
time.sleep(15) |
|
|
break |
|
|
|
|
|
except KeyboardInterrupt as e: |
|
|
|
|
|
pass |
|
|
|
|
|
DbTransfer.del_servers() |
|
|
|
|
|
ServerPool.get_instance().stop() |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
def thread_db_stop(): |
|
|
|
|
|
DbTransfer.get_instance().event.set() |
|
|
|
|
|
|
|
|