Python Forum
Method works as expected on host machine but not on server
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Method works as expected on host machine but not on server
#1
Good morning,

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.
Reply


Messages In This Thread
Method works as expected on host machine but not on server - by gradlon93 - Jan-04-2023, 11:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Custom method to handle exceptions not working as expected gradlon93 3 1,129 Dec-22-2022, 07:12 PM
Last Post: deanhystad
  where to host my python script tomtom 1 1,315 Feb-09-2022, 06:45 AM
Last Post: ndc85430
  Failing to connect to a host with WMI tester_V 6 4,572 Aug-10-2021, 06:25 PM
Last Post: tester_V
  How to take the tar backup files form remote server to local server sivareddy 0 1,992 Jul-14-2021, 01:32 PM
Last Post: sivareddy
Question Google Foobar- Code works in my IDE but not in foobar. Static method? pr3ttykitty 4 5,066 Feb-24-2021, 05:03 PM
Last Post: nilamo
  Fastest Method for Querying SQL Server with Python Pandas BuJayBelvin 7 7,174 Aug-02-2020, 06:21 PM
Last Post: jefsummers
  results for sql server query not as expected kat35601 4 3,231 Sep-13-2018, 08:02 PM
Last Post: kat35601
  Get host from ip antmar904 3 3,034 Jan-31-2018, 08:27 PM
Last Post: antmar904
  Host and port problems for UDP chat server YevesDraco 2 3,876 May-07-2017, 04:35 PM
Last Post: YevesDraco

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020