1
1
import sys
2
2
import threading
3
+ import time
3
4
4
5
from nopdb import nopdb
5
6
from vertx import EventBus
9
10
from sourceplusplus .models .instrument .LiveBreakpoint import LiveBreakpoint
10
11
from sourceplusplus .models .instrument .LiveLog import LiveLog
11
12
from sourceplusplus .models .instrument .LiveMeter import LiveMeter
13
+ from sourceplusplus .models .instrument .common import LiveInstrument
12
14
from sourceplusplus .models .instrument .common .LiveInstrumentType import LiveInstrumentType
13
15
from sourceplusplus .models .instrument .common .LiveSourceLocation import LiveSourceLocation
14
16
@@ -17,12 +19,15 @@ class LiveInstrumentRemote(object):
17
19
instruments = {}
18
20
eb = None
19
21
dbg = None
22
+ cleanupThread = None
20
23
21
24
def __init__ (self , eb : EventBus ):
22
25
LiveInstrumentRemote .eb = eb
23
26
LiveInstrumentRemote .dbg = nopdb .get_nopdb ()
24
27
LiveInstrumentRemote .dbg .start ()
25
28
threading .settrace (sys .gettrace ())
29
+ LiveInstrumentRemote .cleanupThread = threading .Thread (target = self .cleanup , daemon = True )
30
+ LiveInstrumentRemote .cleanupThread .start ()
26
31
27
32
def add_live_instrument (self , command : LiveInstrumentCommand ):
28
33
for inst_dict in command .instruments :
@@ -79,3 +84,18 @@ def handle_instrument_command(self, command: LiveInstrumentCommand):
79
84
self .add_live_instrument (command )
80
85
elif command .command_type == CommandType .REMOVE_LIVE_INSTRUMENT :
81
86
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