Skip to content

Commit fc507af

Browse files
author
xy
committed
messages queue fix, cleanup
1 parent 9af456f commit fc507af

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/core.py

+8-19
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,11 @@ def kill_subprocess(subproc,print_func=print):
228228

229229
if windows:
230230
kill_cmd = ['taskkill', '/F', '/T', '/PID', str(pid)]
231-
#print_func( ('info',f'executing: {kill_cmd}') )
232231
print_func( ('info',f'killing pid: {pid}') )
233232
subprocess_run(kill_cmd)
234233
else:
235234
print_func( ('info',f'killing process group of pid {pid}') )
236235
killpg(getpgid(pid), SIGTERM)
237-
#print_func( ('info',f'killing process group done') )
238236

239237
except Exception as ke:
240238
print_func( ('error',f'kill_subprocess error: {ke}') )
@@ -1263,10 +1261,6 @@ def create(self,label='',scan_path=''):
12631261
self.update_sorted()
12641262
return new_record
12651263

1266-
#def load_record(self):
1267-
#self.records.add(new_record)
1268-
# pass
1269-
12701264
def read_records_pre(self):
12711265
try:
12721266
with scandir(self.db_dir) as res:
@@ -1527,7 +1521,6 @@ def create_new_record(self,temp_dir,update_callback):
15271521
self.log.info(f'create_new_record')
15281522
self_log_info = self.log.info
15291523

1530-
15311524
new_file_path = sep.join([self.db_dir,f'rep.{int(time())}.dat'])
15321525

15331526
command = self.record_exe()
@@ -1613,7 +1606,6 @@ def threaded_run(command,results_semi_list,info_semi_list,processes_semi_list):
16131606
else:
16141607
info_semi_list[0]=line_strip
16151608
except Exception as e:
1616-
print(f'threaded_run work error:{e} line:{line}')
16171609
info_semi_list[0]=f'threaded_run work error:{e} line:{line}'
16181610
self_log_info(f'threaded_run work error:{e} line:{line}')
16191611
else:
@@ -1629,15 +1621,13 @@ def threaded_run(command,results_semi_list,info_semi_list,processes_semi_list):
16291621
job.start()
16301622
job_is_alive = job.is_alive
16311623

1632-
aborted=False
16331624
###########################################
16341625
while job_is_alive():
16351626
subprocess=processes_semi_list[0]
16361627
if subprocess:
16371628
if self.abort_action:
16381629
send_signal(subprocess,temp_dir,0)
16391630
self.abort_action=False
1640-
aborted=True
16411631
if self.abort_action_single:
16421632
send_signal(subprocess,temp_dir,1)
16431633
self.abort_action_single=False
@@ -1646,15 +1636,15 @@ def threaded_run(command,results_semi_list,info_semi_list,processes_semi_list):
16461636
job.join()
16471637
###########################################
16481638

1649-
if not aborted:
1650-
new_record = self.create()
1639+
#nie wiadomo czy przerwano na skanie czy cde
1640+
new_record = self.create()
16511641

1652-
if res:=new_record.load(new_file_path) :
1653-
self.log.warning('removing:%s',new_file_path)
1654-
self.records.remove(new_record)
1655-
print(res)
1656-
else:
1657-
update_callback(new_record)
1642+
if res:=new_record.load(new_file_path) :
1643+
self.log.warning('removing:%s',new_file_path)
1644+
self.records.remove(new_record)
1645+
self_log_info(res)
1646+
else:
1647+
update_callback(new_record)
16581648

16591649
return True
16601650

@@ -1721,7 +1711,6 @@ def find_items_in_records(self,
17211711
############################################################
17221712

17231713
max_processes = cpu_count()
1724-
#max_processes = 1
17251714

17261715
records_to_process_len = len(records_to_process)
17271716

src/record.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,40 @@ def caretaker(signal_file):
126126
sys_stdout_flush = sys.stdout.flush
127127
lines_non_stop=0
128128

129+
def flush_last_data_not_printed(flush):
130+
nonlocal last_data_not_printed
131+
if last_data_not_printed:
132+
print(json_dumps(last_data_not_printed),flush=flush)
133+
last_data_not_printed=None
134+
129135
while True:
130136
now=perf_counter()
137+
now_grater_than_next_time_print = bool(now>next_time_print)
131138

132139
if stdout_data_queue:
133140
data,always=stdout_data_queue_get()
134141

135142
if data==True:
136143
break
137144

138-
if always or now>next_time_print:
145+
if always:
146+
flush_last_data_not_printed(False)
147+
148+
if always or now_grater_than_next_time_print:
139149
print(json_dumps(data),flush=True)
140150
next_time_print=now+print_min_time_period
151+
lines_non_stop+=1
152+
last_data_not_printed=None
141153
else:
142154
last_data_not_printed=data
143-
lines_non_stop+=1
144155

145-
if lines_non_stop<100:
156+
if lines_non_stop<128:
146157
continue
147-
else:
148-
lines_non_stop=0
158+
159+
lines_non_stop=0
160+
161+
if now_grater_than_next_time_print:
162+
flush_last_data_not_printed(True)
149163

150164
if now>next_signal_file_check:
151165
next_signal_file_check=now+signal_file_check_period
@@ -160,10 +174,6 @@ def caretaker(signal_file):
160174
except Exception as pe:
161175
print_info(f'check_abort error:{pe}')
162176

163-
if last_data_not_printed and now>next_time_print:
164-
print(json_dumps(last_data_not_printed),flush=True)
165-
last_data_not_printed=None
166-
167177
sleep(0.01)
168178

169179
sys.exit(0) #thread

0 commit comments

Comments
 (0)