Я пытаюсь выйти из этого кода с помощью CTRL F2 или или закрываю процесс кнопкой остановки, но предложение finally никогда не вызывается.Я хотел бы, когда я остановлю процесс, чтобы записать данные в файл.
for root, dirnames, files in os.walk(r"c:\ahmed\SpeedFT-meter12\peakdata"):
for name in files:
timeStamps.append(name.replace('peakdata_','').replace('.bz2',''))
print(name.replace('peakdata_','').replace('.bz2',''))
i = 0
try:
for dirpath, dirnames, filenames in os.walk(r"C:\ahmed\SpeedFT-meter12\peakdata"):
for filename in [f for f in filenames if f.endswith(".bz2")]:
path = os.path.join(dirpath, filename)
print(path)
process_data(path, i)
except KeyboardInterrupt:
pass
finally:
print("writing data")
general_pd['TimeStamp'] = TimeStamp
general_pd['S_strain_HOY'] = S1
general_pd['S_strain_HMY'] = S2
general_pd['S_strain_HUY'] = S3
general_pd['S_strain_ROX'] = S4
general_pd['S_strain_LOX'] = S5
general_pd['S_strain_LMX'] = S6
general_pd['S_strain_LUX'] = S7
general_pd['S_strain_VOY'] = S8
general_pd['S_temp_HOY'] = T1
general_pd['S_temp_HMY'] = T2
general_pd['S_temp_HUY'] = T3
general_pd['S_temp_LOX'] = T4
general_pd['S_temp_LMX'] = T5
general_pd['S_temp_LUX'] = T6
writer = pd.ExcelWriter(r'c:\ahmed\median_data.xlsx', engine='xlsxwriter')
# Convert the dataframe to an XlsxWriter Excel object.
general_pd.to_excel(writer, sheet_name='Sheet1')
# Close the Pandas Excel writer and output the Excel file.
writer.save()