D
D
del4pp2020-08-25 09:55:04
Python
del4pp, 2020-08-25 09:55:04

The program itself turns off without errors, how to make it work forever?

Hello.
There is a program that works correctly, 3-4 hours on the server (I run it through python3 main.py & exit), after that it turns off without error messages.

I will not expose the program code, because there is a lot there.
If you run it on the server without & exit, and look in the debug console (prints), it works as it should, but if you run it in the background, it crashes.

if __name__ == "__main__":
    while True:
        try:
            main()
        except Exception as e:
            logging_time_update.add_time_update(e)
            time.sleep(5)


logging_time_update.add_time_update(e) - takes a text value, and adds the time to the database, and the text that I pass to the function.
Everything else works in the same handler in the main function.
When the program stops working - only the last run time is displayed in the database, without error information.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2020-08-25
@del4pp

python3 main.py & disown & exit
Better yet, log what she writes:
python3 main.py > main.log 2>&1 & disown & exit

D
Dr. Bacon, 2020-08-25
@bacon

After an error, let it fall quietly, restart not through while True, but with external software, for example, service on systemd. Well, it’s better to log using standard means to a file than to a database, otherwise it can shut up on this request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question