Replace Manager.clean_objects() by the extended version from main

and call it upon the Manager start.
This commit is contained in:
Lee Miller 2023-08-15 02:46:45 +03:00
parent 45a4a8fd31
commit 8755e56167
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 10 additions and 16 deletions

View File

@ -300,18 +300,6 @@ def main():
# so we can collect I2P destination objects
start_i2p_listener()
for vector in set(shared.objects):
if not shared.objects[vector].is_valid():
if shared.objects[vector].is_expired():
logging.debug(
'Deleted expired object: %s',
base64.b16encode(vector).decode())
else:
logging.warning(
'Deleted invalid object: %s',
base64.b16encode(vector).decode())
del shared.objects[vector]
manager = Manager()
manager.start()

View File

@ -28,6 +28,7 @@ class Manager(threading.Thread):
time.time() - 50 * 60 + random.uniform(-1, 1) * 300 # nosec
def run(self):
self.clean_objects()
while True:
time.sleep(0.8)
now = time.time()
@ -53,12 +54,17 @@ class Manager(threading.Thread):
@staticmethod
def clean_objects():
for vector in set(shared.objects):
if shared.objects[vector].is_expired():
if not shared.objects[vector].is_valid():
if shared.objects[vector].is_expired():
logging.debug(
'Deleted expired object: %s',
base64.b16encode(vector).decode())
else:
logging.warning(
'Deleted invalid object: %s',
base64.b16encode(vector).decode())
with shared.objects_lock:
del shared.objects[vector]
logging.debug(
'Deleted expired object: %s',
base64.b16encode(vector).decode())
@staticmethod
def manage_connections():