For some reasons my python doesn't execute the actions in the elif clause:
elif server.system_state == SystemState_Standby \
The server.system_state is assigned to System_State_Standy before, i could figure that out while debugging. So the elif condition should be true
Im running Python 3.6 with PyCharm on a Windows Notebook.
Here's a part of my code (sorry for bad pasting, i'm new to StackOverflow. Everything is inside the while loop):
# loop over application tasks
while True:
start_time = datetime.datetime.now()
#Variable for user input to ignore missing battery systems
user_subm = 'default'
# initialization
if server.system_state == SystemState_Initialize:
# connect to database
result = connect_database()
print_result(result, level)
if result[0] is False:
print_result([False, failure_message])
input("\n>>> Press any key to restart the application. <<<\n")
print_result([False, restart_message])
continue
# define server thread
result = create_thread(check_server_thread, [server, ])
print_result(result, level)
if result[0] is False:
result = log_application_error("A000", failure_message, str(result[1]), None, None)
print_result(result, level)
print_result([False, failure_message])
input("\n>>> Press any key to restart the application. <<<\n")
print_result([False, restart_message])
continue
server.thread_identifier_1 = result[1]
# define client thread
result = create_thread(check_client_threads, [client, ])
print_result(result, level)
if result[0] is False:
result = log_application_error("A001", failure_message, str(result[1]), None, None)
print_result(result, level)
print_result([False, failure_message])
input("\n>>> Press any key to restart the application. <<<\n")
print_result([False, restart_message])
continue
client.thread_identifier_1 = result[1]
server.system_state = SystemState_Update
server.last_state_update = datetime.datetime.now()
server.update_dynamic_data()
# add battery systems
elif server.system_state == SystemState_Update:
if client.thread_active_1 is True:
# initiate shutdown sequence of client
client.thread_active_1 = False
client.thread_identifier_1.join(60)
if server.thread_active_1 is True:
# initiate shutdown sequence of server
server.thread_active_1 = False
server.thread_identifier_1.join(60)
# add new battery systems to database or change connection information if necessary
result = client.add_battery_systems()
print_result(result, level)
if result[0] is False:
result = log_application_error("A100", failure_message, str(result[1]), None, None)
print_result(result, level)
print_result([False, failure_message])
user_subm = input("\n>>> Press r to restart the application. Pres c to continue the application \
even tough no Battery System is connected. <<<\n") #TODO: Get rid of spaces in the print message
if user_subm == 'c':
print ("Application continued with no Battery System connected") #TODO: Update to usual print sytle
elif user_subm == 'r':
print_result([False, restart_message])
continue
server.system_state = SystemState_Connect
server.last_state_update = datetime.datetime.now()
server.update_dynamic_data()
#Skip connecting battery systems if requested so by user
if user_subm == 'c':
server.system_state = SystemState_Standby
server.last_state_update = datetime.datetime.now()
server.update_dynamic_data()
#TODO: Add Log Archive entry
# check server and client threads
elif server.system_state == SystemState_Standby \
or server.system_state == SystemState_Charge \
or server.system_state == SystemState_Discharge:
server.grid_control_automatic_mode = True
# check server thread
try:
if server.thread_identifier_1.isAlive() is False:
if server.thread_identifier_1._Thread__stopped is True:
# define server thread
result = create_thread(check_server_thread, [server, ])
print_result(result, level)
if result[0] is False:
result = log_application_error("A300", failure_message, str(result[1]), None, None)
print_result(result, level)
print_result([True, failure_message])
sys.exit()
server.thread_identifier_1 = result[1]
server.thread_identifier_1.start()
except Exception as ThreadError:
result = log_application_error("A301", exception_message, str(ThreadError), None, None)
print_result(result, level)
print_result([True, exception_message])
sys.exit()
# wait for server to be ready
time.sleep(1)
# check client thread
try:
if client.thread_identifier_1.isAlive() is False:
if client.thread_identifier_1._Thread__stopped is True:
# define server thread
result = create_thread(check_client_threads, [client, ])
print_result(result, level)
if result[0] is False:
result = log_application_error("A302", failure_message, str(result[1]), None, None)
print_result(result, level)
print_result([True, failure_message])
sys.exit()
client.thread_identifier_1 = result[1]
client.thread_identifier_1.start()
except Exception as ThreadError:
result = log_application_error("A303", exception_message, str(ThreadError), None, None)
print_result(result, level)
print_result([True, exception_message])
sys.exit()
Aucun commentaire:
Enregistrer un commentaire