Jan-04-2023, 11:48 AM
Good morning,
I have written the following script, which should run a method recursively until the constant
On the server (SSH connection), it just never exits the while loop.
Any idea of why this would happen?
I tried different ways to refactor my code but anything seems to work.
I have written the following script, which should run a method recursively until the constant
SIGN_COLOR
from an external .ini
file is RED
.#!/usr/bin/env python ''' Runs a method recursively, until SIGN_COLOR is "RED". ''' from configparser import ConfigParser from datetime import date, datetime import time constants = ConfigParser() constants.read('traffic_light.ini') counter = 1 current_color = constants.get('CONSTANTS', 'SIGN_COLOR') def recursion(*args, **kwargs): with open('timecount.html', 'a') as html_output: html_output.write( f'#{"{:08d}".format(counter)} | {date.today()} | <b>{datetime.now().strf> ) time.sleep(1) while current_color != 'RED': recursion() counter += 1 with open('timecount.html', 'a') as html_output: html_output.write('<p><font color="red">Ending cycle from signal "RED".</font></>Content of
traffic_light.ini
:; traffic_light.ini [CONSTANTS] SIGN_COLOR="GREEN"On the host machine (Pycharm IDE) I run the script, the
while
loop goes on, then whenever I externally change the constant it will exit the loop and behave as expected. On the server (SSH connection), it just never exits the while loop.
Any idea of why this would happen?
I tried different ways to refactor my code but anything seems to work.