-2

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?

Kuki
  • 33
  • 7

2 Answers2

0

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.

Daraan
  • 1,797
  • 13
  • 24
0

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

MadDy
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 03 '23 at 13:30