skip to Main Content

I have a Telegram bot based on free pythonanywhere servers. So, what’s the problem? For some reason the execution is stopped from time to time and no errors are displayed in the console.Example.

I need my bot to be active all the time. What do I do?

2

Answers


  1. On a very general level you can restart your app like this in the same file or from another file

    from your_app import main
    
    while True:
       try:
          main() # assuming this has a blocking loop as well
       except Exception as e:
          print(e) # or log it in some way
       print("Restarting main")
    

    Even if main terminates without an error it will restart.
    You might need to do some clean up beforehand.

    More specific to your problem:
    There always could be an option that an error is silently suppressed and your code ends or something with the server, which will not show up on the console.

    Login or Signup to reply.
  2. 1)Create a batch file and run your Main.py file
    2)Schedule it with the windows task scheduler with created batch file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search