Manage client lifecycle with idle and stop
maintg.idle()
Blocks the script and waits for an exit signal. By default, it listens for SIGINT, SIGTERM, and SIGABRT. You can customize these via the stop_signals parameter. When a signal is received, idle() automatically calls stop() for you.
tg.stop()
You must call stop() to shut down python-telegram and tdlib cleanly. It invokes the close method of tdlib and waits for it to finish. If you are using idle(), you can trigger a shutdown by calling stop() from a different thread.