mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-13 19:27:58 +01:00
Improve signal handling
This commit is contained in:
parent
0b72acc7c8
commit
1005ad57ce
2 changed files with 13 additions and 6 deletions
|
@ -67,7 +67,8 @@ def main():
|
|||
# Start the Bot
|
||||
updater.start_polling(timeout=5)
|
||||
|
||||
# Run the bot until the user presses Ctrl-C
|
||||
# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
|
||||
# SIGTERM or SIGABRT
|
||||
updater.idle()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -234,11 +234,17 @@ class Updater:
|
|||
self.is_idle = False
|
||||
self.stop()
|
||||
|
||||
def idle(self):
|
||||
""" Waits for the user to press Ctrl-C and stops the updater """
|
||||
signal(SIGINT, self.signal_handler)
|
||||
signal(SIGTERM, self.signal_handler)
|
||||
signal(SIGABRT, self.signal_handler)
|
||||
def idle(self, stop_signals=(SIGINT, SIGTERM, SIGABRT)):
|
||||
"""
|
||||
Waits for the user to press Ctrl-C and stops the updater
|
||||
|
||||
Args:
|
||||
stop_signals: Iterable containing signals from the signal module
|
||||
that should be subscribed to. Updater.stop() will be called on
|
||||
receiving one of those signals.
|
||||
"""
|
||||
for sig in stop_signals:
|
||||
signal(sig, self.signal_handler)
|
||||
|
||||
self.is_idle = True
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue