which python trick or hack you know that you would want to share?

whoareu@lemmy.ca to Programming@programming.dev – 95 points –
45

You are viewing a single comment

My secret to high uptime:

while True:
    try:
        main()
    except:
        pass

Someone is absolutely going to think this is a real recommendation and do it.

Lurking beginner here, why is this bad?

Basically sweeps errors under rug.

No error handling and go again.

There you go:

# Start an infinite loop because True will always be True
while True: 
    # try to run the main function, usually where everything happens
    try:
        main()
    # in the case an exception is raised in the main function simply discard (pass) and restart the loop
    except:
        pass
1 more...