Full-proof on exit method in Python

  atexit, discord.py, python-3.8, shutdown, windows

I want to run a Discord Bot on my computer, and I want to write a function that makes sure the discord server doesn’t break when my computer shuts down. The problem is when I shutdown my computer or close the console window the exit handling code isn’t run. I think this is because os._exit() is called to terminate it.

Is there any way to make an exit function that runs no matter which exit call the computer makes to the program? How is it when I shut down my computer sometimes a program refuses to close, how can I achieve this?

I’ve tried using multiexit which is supposed to be a more complex version of atexit but it still won’t work.

Can I force windows to gracefully shut down my program?

Source: Windows Questions

LEAVE A COMMENT