mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-28 00:56:19 +00:00
Add idle mechanism to gently stop the program
This commit is contained in:
parent
c83daf8771
commit
b6607fede0
@ -26,6 +26,8 @@ import time
|
||||
from collections import namedtuple
|
||||
from configparser import ConfigParser
|
||||
from hashlib import sha256, md5
|
||||
from signal import signal, SIGINT, SIGTERM, SIGABRT
|
||||
from threading import Event
|
||||
|
||||
from pyrogram.api import functions, types
|
||||
from pyrogram.api.core import Object
|
||||
@ -71,6 +73,7 @@ class Client:
|
||||
self.session = None
|
||||
|
||||
self.update_handler = None
|
||||
self.is_idle = Event()
|
||||
|
||||
# TODO: Better update handler
|
||||
def set_update_handler(self, callback: callable):
|
||||
@ -79,6 +82,16 @@ class Client:
|
||||
def send(self, data: Object):
|
||||
return self.session.send(data)
|
||||
|
||||
def signal_handler(self, *args):
|
||||
self.stop()
|
||||
self.is_idle.set()
|
||||
|
||||
def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)):
|
||||
for s in stop_signals:
|
||||
signal(s, self.signal_handler)
|
||||
|
||||
self.is_idle.wait()
|
||||
|
||||
def authorize(self):
|
||||
while True:
|
||||
phone_number = input("Enter phone number: ")
|
||||
|
Loading…
Reference in New Issue
Block a user