This is a simple script that is used to calculate Z scores of some neuropsychological tests.
But recently the code seems to be running on the background even after exiting the program. This problem didn't exist before, I use the following startup piece to ensure program is running with elevation, and is correct size for the display.
Program can be shut down using a "exit" command that raises SystemExit or just by pressing the X button on the top bar. Program keep running on the background regardless.
Where did I go wrong?
def progStructure():
first_run = True
if first_run:
import os
os.system("mode con: cols=160 lines=50")
print("""
================================================
PROGRAM GREETING
================================================
""")
mainStartup()
first_run = False
while settings("auto_run"):
mainStartup()
#this function contains the main program, but irrelevant to the question
print("Auto shutdown enabled, program is shutting down.")
wait(2)
exit()
#informs the user data has been saved then restarts
import ctypes, sys
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin():
progStructure()
else:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, "", None, 0)
progStructure()
My excel writing function:
def excelWriter(excel_path, data_num, printable_list):
from time import strftime
date = strftime("%Y-%m-%d")
time = strftime("%H:%M:%S")
if settings("excel_output_subjectNames"):
patient_name_local = patient_name
else:
patient_name_local = "N/A"
demographic_data = [patient_ID, patient_name_local, patient_admin, date, time, patient_age, patient_sex, patient_edu]
from openpyxl import Workbook
from openpyxl import load_workbook
wb = Workbook(write_only=False)
try:
test_name_list = [
"(1)MMT", "(2)MOCA", "(3)3MS", "(4)GISD", "(5)ECR",
"(6)Sözel Bellek Süreçleri", "(7)Rey Karmaşık Figür", "(8)İz Sürme", "(9)Stroop",
"(10)Wisconsin", "(11)Görsel Sözel Test", "(12)Renkli İz Sürme",
"(13)Wechsler", "(14)Wechsler-Sayı Dizisi", "(15)Sözel Akıcılık",
"(16)Semantik Akıcılık", "(17)Saat Çizme", "(18)SDOT", "(19)Ayları İleri-Geri Sayma"
]
while True:
try:
data_workbook = load_workbook(filename = excel_path + settings("excel_name"), read_only=False)
active_sheet = data_workbook.get_sheet_by_name(test_name_list[data_num-1])
active_sheet.append(demographic_data + printable_list)
data_workbook.save(filename = excel_path + settings("excel_name"))
break
except:
for i in range(len(test_name_list)):
wb.create_sheet(title = test_name_list[i])
wb.save(filename = excel_path + settings("excel_name"))
data_workbook = load_workbook(filename = excel_path + settings("excel_name"), read_only=False)
active_sheet = data_workbook.get_sheet_by_name("Sheet")
data_workbook.remove_sheet(active_sheet)
data_workbook.save(filename = excel_path + settings("excel_name"))
continue
except:
raise
写完之后忘了关闭excel文件,看似已解决了问题,感谢大家的帮助。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.