From 9b83f7575acb1e95e1ad3ab711d12c0bd8825be3 Mon Sep 17 00:00:00 2001 From: Akshay Praveen Nair Date: Mon, 18 May 2020 04:36:02 +0530 Subject: [PATCH] Nawab: Fix the keyboard Interrupt This commit fixes #58 --- nawab.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/nawab.py b/nawab.py index e0402a9..ed7a05d 100644 --- a/nawab.py +++ b/nawab.py @@ -3,6 +3,7 @@ import pandas as pd import pwd import os +import sys import threading import argparse import logging @@ -45,11 +46,17 @@ def tg_bot_run(self, auto_retweet=None): dp.add_error_handler(bot.error) # Start the Bot - updater.start_polling() # Run the bot until the user presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT - updater.idle() + try: + updater.start_polling() + except KeyboardInterrupt: + try: + sys.exit(1) + except SystemExit: + os._exit(1) + def wrapper(func, args, res): @@ -119,5 +126,11 @@ def main(): nawab.tg_bot_run() -if __name__ == "__main__": - main() +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + try: + sys.exit(1) + except SystemExit: + os._exit(1)