From 0f100b15ab9209fa6175290848720be5650e56e8 Mon Sep 17 00:00:00 2001 From: 3err0 Date: Mon, 24 Jun 2019 10:02:57 +0800 Subject: [PATCH] remove pid if finally --- main.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 3c99769..62f5125 100644 --- a/main.py +++ b/main.py @@ -58,11 +58,15 @@ def handle_file(message): except Exception as e: bot.reply_to(message,e ) -try: +if __name__ == '__main__': pid = str(os.getpid()) - pidfile = open(config.pid, 'w') - pidfile.write(pid) - pidfile.close() - bot.polling(none_stop=True, interval=0, timeout=10) -except Exception as e: - print(e) \ No newline at end of file + pidf = config.pid + try: + pidfile = open(pidf, 'w') + pidfile.write(pid) + pidfile.close() + bot.polling(none_stop=True, interval=0, timeout=10) + except Exception as e: + print(e) + finally: + os.remove(pidf) \ No newline at end of file