11import sys
22import threading
3+ import time
34
45from nopdb import nopdb
56from vertx import EventBus
910from sourceplusplus .models .instrument .LiveBreakpoint import LiveBreakpoint
1011from sourceplusplus .models .instrument .LiveLog import LiveLog
1112from sourceplusplus .models .instrument .LiveMeter import LiveMeter
13+ from sourceplusplus .models .instrument .common import LiveInstrument
1214from sourceplusplus .models .instrument .common .LiveInstrumentType import LiveInstrumentType
1315from sourceplusplus .models .instrument .common .LiveSourceLocation import LiveSourceLocation
1416
@@ -17,12 +19,15 @@ class LiveInstrumentRemote(object):
1719 instruments = {}
1820 eb = None
1921 dbg = None
22+ cleanupThread = None
2023
2124 def __init__ (self , eb : EventBus ):
2225 LiveInstrumentRemote .eb = eb
2326 LiveInstrumentRemote .dbg = nopdb .get_nopdb ()
2427 LiveInstrumentRemote .dbg .start ()
2528 threading .settrace (sys .gettrace ())
29+ LiveInstrumentRemote .cleanupThread = threading .Thread (target = self .cleanup , daemon = True )
30+ LiveInstrumentRemote .cleanupThread .start ()
2631
2732 def add_live_instrument (self , command : LiveInstrumentCommand ):
2833 for inst_dict in command .instruments :
@@ -79,3 +84,18 @@ def handle_instrument_command(self, command: LiveInstrumentCommand):
7984 self .add_live_instrument (command )
8085 elif command .command_type == CommandType .REMOVE_LIVE_INSTRUMENT :
8186 self .remove_live_instrument (command )
87+
88+ def cleanup (self ):
89+ while True :
90+ time .sleep (1 )
91+ delete = []
92+ for key , val in LiveInstrumentRemote .instruments .items ():
93+ instrument : LiveInstrument = val [1 ]
94+ if instrument .expires_at is not None and instrument .expires_at <= round (time .time () * 1000 ):
95+ delete .append (key )
96+ for key in delete :
97+ instrument : LiveInstrument = LiveInstrumentRemote .instruments .pop (key )[1 ]
98+ LiveInstrumentRemote .eb .send (address = "spp.processor.status.live-instrument-removed" , body = {
99+ "instrument" : instrument .to_json (),
100+ "occurredAt" : round (time .time () * 1000 )
101+ })
0 commit comments