Skip to content

Commit 47caa5b

Browse files
committed
Add thread to remove expired instruments
1 parent f8872a2 commit 47caa5b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sourceplusplus/control/LiveInstrumentRemote.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import threading
3+
import time
34

45
from nopdb import nopdb
56
from vertx import EventBus
@@ -17,12 +18,15 @@ class LiveInstrumentRemote(object):
1718
instruments = {}
1819
eb = None
1920
dbg = None
21+
cleanupThread = None
2022

2123
def __init__(self, eb: EventBus):
2224
LiveInstrumentRemote.eb = eb
2325
LiveInstrumentRemote.dbg = nopdb.get_nopdb()
2426
LiveInstrumentRemote.dbg.start()
2527
threading.settrace(sys.gettrace())
28+
LiveInstrumentRemote.cleanupThread = threading.Thread(target=self.cleanup)
29+
LiveInstrumentRemote.cleanupThread.start()
2630

2731
def add_live_instrument(self, command: LiveInstrumentCommand):
2832
for inst_dict in command.instruments:
@@ -79,3 +83,12 @@ def handle_instrument_command(self, command: LiveInstrumentCommand):
7983
self.add_live_instrument(command)
8084
elif command.command_type == CommandType.REMOVE_LIVE_INSTRUMENT:
8185
self.remove_live_instrument(command)
86+
87+
def cleanup(self):
88+
while True:
89+
delete = []
90+
for key, val in LiveInstrumentRemote.instruments.items():
91+
if "expires_at" in val[1] and val[1]["expires_at"] < round(time.time() * 1000):
92+
delete.append(key)
93+
for key in delete:
94+
del LiveInstrumentRemote.instruments[key]

0 commit comments

Comments
 (0)