mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-11-19 14:36:34 -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()
|
||||
|
||||
__instance = None
|
||||
__pid = os.getpid()
|
||||
|
||||
__interface_detach_ran = False
|
||||
__exit_handler_ran = False
|
||||
|
|
@ -186,6 +187,9 @@ class Reticulum:
|
|||
# shut down, and will in turn call exit handlers in other
|
||||
# classes, saving necessary information to disk and carrying
|
||||
# out cleanup operations.
|
||||
if not os.getpid() == Reticulum.__pid:
|
||||
Reticulum.__exit_handler_ran = True
|
||||
|
||||
if not Reticulum.__exit_handler_ran:
|
||||
Reticulum.__exit_handler_ran = True
|
||||
|
||||
|
|
@ -194,10 +198,11 @@ class Reticulum:
|
|||
except Exception: pass
|
||||
|
||||
try:
|
||||
deregister_job = threading.Thread(target=Reticulum.__instance.unwants_all_destination_types, daemon=True)
|
||||
deregister_job.start()
|
||||
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)
|
||||
if Reticulum.__instance.is_connected_to_shared_instance:
|
||||
deregister_job = threading.Thread(target=Reticulum.__instance.unwants_all_destination_types, daemon=True)
|
||||
deregister_job.start()
|
||||
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)
|
||||
|
||||
if not Reticulum.__interface_detach_ran: RNS.Transport.detach_interfaces()
|
||||
|
|
@ -209,13 +214,13 @@ class Reticulum:
|
|||
|
||||
@staticmethod
|
||||
def sigint_handler(signal, frame):
|
||||
RNS.Transport.detach_interfaces()
|
||||
if os.getpid() == Reticulum.__pid: RNS.Transport.detach_interfaces()
|
||||
Reticulum.__interface_detach_ran = True
|
||||
RNS.exit()
|
||||
|
||||
@staticmethod
|
||||
def sigterm_handler(signal, frame):
|
||||
RNS.Transport.detach_interfaces()
|
||||
if os.getpid() == Reticulum.__pid: RNS.Transport.detach_interfaces()
|
||||
Reticulum.__interface_detach_ran = True
|
||||
RNS.exit()
|
||||
|
||||
|
|
@ -226,6 +231,13 @@ class Reticulum:
|
|||
"""
|
||||
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,
|
||||
require_shared_instance=False, shared_instance_type=None,
|
||||
enable_stamping=False, enforce_stamps=False):
|
||||
|
|
|
|||
|
|
@ -422,6 +422,11 @@ def generate_stamped_key(material, stamp_cost):
|
|||
|
||||
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):
|
||||
if RNS.vendor.platformutils.is_windows() or RNS.vendor.platformutils.is_darwin():
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -4856,6 +4856,7 @@ class Transport:
|
|||
|
||||
@staticmethod
|
||||
def exit_handler():
|
||||
if not os.getpid() == RNS.Reticulum.get_instance_pid(): return
|
||||
Transport._should_run = False
|
||||
Transport.void_queues()
|
||||
if not Transport.owner.is_connected_to_shared_instance:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue