@@ -63,6 +63,12 @@ def the_task(self, data, the_process):
6363
6464
6565 if process_checked :
66+ process_monitor_dict [data ] = the_process
67+ the_list = list (process_monitor_dict .keys ())
68+ the_list .append ("ALL" )
69+ TPClient .choiceUpdate (choiceId = PLUGIN_ID + ".act.process_name.stop" , values = the_list )
70+ ## update a state showing how many values are in the list minus the "ALL" value
71+ TPClient .stateUpdate (stateId = PLUGIN_ID + ".state.process_monitor.count" , stateValue = str (len (the_list ) - 1 ))
6672
6773 print (f"{ the_process .process_name } is running" )
6874
@@ -108,6 +114,7 @@ def check_continuously(self, interval, data, the_process):
108114
109115 def stop (self ):
110116 self .should_continue = False
117+
111118
112119
113120
@@ -164,6 +171,8 @@ def onConnect(data):
164171 if settings := data .get ('settings' ):
165172 handleSettings (settings , True )
166173
174+ TPClient .stateUpdate (stateId = PLUGIN_ID + ".state.process_monitor.count" , stateValue = "0" )
175+
167176
168177
169178
@@ -208,7 +217,7 @@ def onSettingUpdate(data):
208217# ## use a thread to create sttes as fast as possible
209218# TPClient.createState(stateId=PLUGIN_ID + f".state.{the_process.process_name}.process_info.{x}", description=f"PM | {the_process.process_name} - {x}", value=str(process_checked.get(x, "None")), parentGroup=str(the_process.process_name))
210219
211-
220+ process_monitor_dict = {}
212221
213222@TPClient .on (TP .TYPES .onAction )
214223def onAction (data ):
@@ -228,36 +237,36 @@ def onAction(data):
228237 #the_process.time_completion(data=data['data'][0]['value'], the_process=the_process)
229238 the_process .the_task (data = data , the_process = the_process )
230239 else :
231- print (f"We are gonna check every { str (data ['data' ][1 ]['value' ])} seconds" )
240+ print (f"Checking every { str (data ['data' ][1 ]['value' ])} seconds for { data [ 'data' ][ 0 ][ 'value' ] } " )
232241 the_process = ProcessChecker (data ['data' ][0 ]['value' ])
233242 process_checked = the_process .check_continuously (int (data ['data' ][1 ]['value' ]), data = data ['data' ][0 ]['value' ], the_process = the_process )
234- # print(process_checked)
235-
236-
237- # the_process = ProcessChecker(data['data'][0]['value'])
238- # process_checked = the_process.get_process_info()
239- # if process_checked:
240- # g_log.info(f"{the_process.process_name} is running")
241- #
242- # g_log.debug(f"Process Info: {process_checked}")
243- #
244- # print(process_checked)
245- # for x in process_checked:
246- # if x == 'memory_percent':
247- # ## Round it to the 2nd decimal place
248- # process_checked[x] = round(process_checked[x], 2)
249- #
250- # if x == 'create_time':
251- # from datetime import datetime
252- # create_time = process_checked.get('create_time', "None")
253- # if create_time is not None:
254- # create_time_datetime = datetime.fromtimestamp(create_time)
255- # process_checked[x] = create_time_datetime.strftime("%m/%d/%Y [%I:%M:%S %p]")
256- #
257- # TPClient.createState(stateId=PLUGIN_ID + f".state.{the_process.process_name}.process_info.{x}", description=f"PM | {the_process.process_name} - {x}", value=str(process_checked.get(x, "None")), parentGroup=str(the_process.process_name))
258-
259243
260244
245+ if data ['actionId' ] == PLUGIN_ID + ".act.stop_process.Monitor" :
246+ global process_monitor_dict
247+ the_process = data ['data' ][0 ]['value' ]
248+ try :
249+ if the_process == "ALL" :
250+ # print("Trying to remove all processes from the dict")
251+ for x in process_monitor_dict :
252+
253+ # print("Stopping the process: ", x)
254+ if x != "ALL" :
255+ process_monitor_dict [x ].stop ()
256+ g_log .debug (stopped_process := f"Stopping the process: { x } " )
257+
258+ process_monitor_dict = {}
259+ else :
260+ process_monitor_dict [the_process ].stop ()
261+ ## delete the key from the dict
262+ # print("Trying to remove the process {} from the dict".format(the_process))
263+ process_monitor_dict .pop (the_process )
264+
265+ TPClient .stateUpdate (stateId = PLUGIN_ID + ".state.process_monitor.count" , stateValue = str (len (process_monitor_dict .keys ())))
266+ # del process_monitor_dict[the_process]
267+ except Exception as e :
268+ print (e )
269+
261270
262271
263272# Shutdown handler
0 commit comments