mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-12-04 05:40:09 -05:00
Only run instance teardown at exit from main process
This commit is contained in:
parent
715707b1bf
commit
e35bd08f18
3 changed files with 24 additions and 6 deletions
|
|
@ -176,6 +176,7 @@ class Reticulum:
|
||||||
gracious_persist_lock = Lock()
|
gracious_persist_lock = Lock()
|
||||||
|
|
||||||
__instance = None
|
__instance = None
|
||||||
|
__pid = os.getpid()
|
||||||
|
|
||||||
__interface_detach_ran = False
|
__interface_detach_ran = False
|
||||||
__exit_handler_ran = False
|
__exit_handler_ran = False
|
||||||
|
|
@ -186,6 +187,9 @@ class Reticulum:
|
||||||
# shut down, and will in turn call exit handlers in other
|
# shut down, and will in turn call exit handlers in other
|
||||||
# classes, saving necessary information to disk and carrying
|
# classes, saving necessary information to disk and carrying
|
||||||
# out cleanup operations.
|
# out cleanup operations.
|
||||||
|
if not os.getpid() == Reticulum.__pid:
|
||||||
|
Reticulum.__exit_handler_ran = True
|
||||||
|
|
||||||
if not Reticulum.__exit_handler_ran:
|
if not Reticulum.__exit_handler_ran:
|
||||||
Reticulum.__exit_handler_ran = True
|
Reticulum.__exit_handler_ran = True
|
||||||
|
|
||||||
|
|
@ -194,10 +198,11 @@ class Reticulum:
|
||||||
except Exception: pass
|
except Exception: pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
deregister_job = threading.Thread(target=Reticulum.__instance.unwants_all_destination_types, daemon=True)
|
if Reticulum.__instance.is_connected_to_shared_instance:
|
||||||
deregister_job.start()
|
deregister_job = threading.Thread(target=Reticulum.__instance.unwants_all_destination_types, daemon=True)
|
||||||
deregister_job.join(timeout=Reticulum.RPC_EXIT_TIMEOUT)
|
deregister_job.start()
|
||||||
if deregister_job.is_alive(): RNS.log("Shared instance RPC timed out during exit", RNS.LOG_DEBUG)
|
deregister_job.join(timeout=Reticulum.RPC_EXIT_TIMEOUT)
|
||||||
|
if deregister_job.is_alive(): RNS.log("Shared instance RPC timed out during exit", RNS.LOG_DEBUG)
|
||||||
except Exception as e: RNS.log(f"Could not deregister destination types at exit: {e}", RNS.LOG_DEBUG)
|
except Exception as e: RNS.log(f"Could not deregister destination types at exit: {e}", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
if not Reticulum.__interface_detach_ran: RNS.Transport.detach_interfaces()
|
if not Reticulum.__interface_detach_ran: RNS.Transport.detach_interfaces()
|
||||||
|
|
@ -209,13 +214,13 @@ class Reticulum:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sigint_handler(signal, frame):
|
def sigint_handler(signal, frame):
|
||||||
RNS.Transport.detach_interfaces()
|
if os.getpid() == Reticulum.__pid: RNS.Transport.detach_interfaces()
|
||||||
Reticulum.__interface_detach_ran = True
|
Reticulum.__interface_detach_ran = True
|
||||||
RNS.exit()
|
RNS.exit()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sigterm_handler(signal, frame):
|
def sigterm_handler(signal, frame):
|
||||||
RNS.Transport.detach_interfaces()
|
if os.getpid() == Reticulum.__pid: RNS.Transport.detach_interfaces()
|
||||||
Reticulum.__interface_detach_ran = True
|
Reticulum.__interface_detach_ran = True
|
||||||
RNS.exit()
|
RNS.exit()
|
||||||
|
|
||||||
|
|
@ -226,6 +231,13 @@ class Reticulum:
|
||||||
"""
|
"""
|
||||||
return Reticulum.__instance
|
return Reticulum.__instance
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_instance_pid():
|
||||||
|
"""
|
||||||
|
Returns the main process ID of the currently running Reticulum instance.
|
||||||
|
"""
|
||||||
|
return Reticulum.__pid
|
||||||
|
|
||||||
def __init__(self,configdir=None, loglevel=None, logdest=None, verbosity=None,
|
def __init__(self,configdir=None, loglevel=None, logdest=None, verbosity=None,
|
||||||
require_shared_instance=False, shared_instance_type=None,
|
require_shared_instance=False, shared_instance_type=None,
|
||||||
enable_stamping=False, enforce_stamps=False):
|
enable_stamping=False, enforce_stamps=False):
|
||||||
|
|
|
||||||
|
|
@ -422,6 +422,11 @@ def generate_stamped_key(material, stamp_cost):
|
||||||
|
|
||||||
return keypair, value
|
return keypair, value
|
||||||
|
|
||||||
|
def cancel_all_work():
|
||||||
|
RNS.log(f"Stopping all stamp workers", RNS.LOG_DEBUG)
|
||||||
|
active_ids = list(active_jobs.keys())
|
||||||
|
for active_id in active_ids: cancel_work(active_id)
|
||||||
|
|
||||||
def cancel_work(message_id):
|
def cancel_work(message_id):
|
||||||
if RNS.vendor.platformutils.is_windows() or RNS.vendor.platformutils.is_darwin():
|
if RNS.vendor.platformutils.is_windows() or RNS.vendor.platformutils.is_darwin():
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -4856,6 +4856,7 @@ class Transport:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
|
if not os.getpid() == RNS.Reticulum.get_instance_pid(): return
|
||||||
Transport._should_run = False
|
Transport._should_run = False
|
||||||
Transport.void_queues()
|
Transport.void_queues()
|
||||||
if not Transport.owner.is_connected_to_shared_instance:
|
if not Transport.owner.is_connected_to_shared_instance:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue