App not running correctly on server

Hello everyone,
i use eNano as instance and PRO plan - at the moment i’m tryng to upload my project but altough it works good in local, it struggles in Koyeb.

It’s a simple API call once everyday - but i cant make it work.

This is what i get from the logs:

Instance created. Preparing to start…
03/19/2025, 10:33:49 PM [2025-03-19 21:33:49 +0000] [1] [INFO] Starting gunicorn 21.2.0
03/19/2025, 10:33:49 PM [2025-03-19 21:33:49 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
03/19/2025, 10:33:49 PM [2025-03-19 21:33:49 +0000] [1] [INFO] Using worker: sync
03/19/2025, 10:33:49 PM [2025-03-19 21:33:49 +0000] [14] [INFO] Booting worker with pid: 14
03/19/2025, 10:33:51 PM Ora server: 2025-03-19 21:33:50.757500
03/19/2025, 10:33:50 PM Instance is starting… Waiting for health checks to pass.
03/19/2025, 10:34:15 PM Instance is healthy. All health checks are passing.

This is the python code, which is real simple:

schedule.every().day.at("23:20:00").do(get_OHLC)
print(f"Ora server: {datetime.datetime.now()}")

def schedule_runner():
    while True:
        print("Checking schedule...")
        schedule.run_pending()
        time.sleep(10) 
        print("Scheduled tasks completed.")

def start_flask():
    print("Starting function start_flask")
    app = Flask(__name__)
    app.run(debug=False, use_reloader=False)
    print("Flask avviato")

if __name__ == "__main__":
    print("Starting Flask and Scheduler")
    schedule_thread = threading.Thread(target=schedule_runner, daemon=True)
    schedule_thread.start()
    print("Starting scheduling thread")

    flask_thread = threading.Thread(target=start_flask, daemon=False)
    flask_thread.start()
    print("Starting flask thread")

    while True:
        time.sleep(1)  # Mantieni il programma attivo
        print("Programma attivo")

Still i struggle to make it work, as you can see it shows the message “Ora server:”, but nothing else - but if i click on the koyeb’s server link - it returns me the message expected which is “Your server is working fine”

Hope you can help, thank you very much!

Hello @Maurizio,

How do you start it locally? In logs I see gunicorn logs

Hello Lukasz, thank you for your help - it seems that the problem was a line of code on the threading function that indeed was working well in the local (without running gunicorn but using “Run” on VSCode)
Then the problem arises only when running with gunicorn

I solved the issue yesterday nigh modifying the thread.
Thank you very much for your time and for your help!

1 Like