mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Enhance API by adding support for Context Managers. Closes #122
A batch script would be as simple as this example: from pyrogram import Client with Client("...") as app: app.send_message("haskell", "hi")
This commit is contained in:
parent
cd3649448c
commit
f850d6352e
@ -183,6 +183,13 @@ class Client(Methods, BaseClient):
|
||||
|
||||
self.dispatcher = Dispatcher(self, workers)
|
||||
|
||||
def __enter__(self):
|
||||
self.start()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.stop()
|
||||
|
||||
@property
|
||||
def proxy(self):
|
||||
return self._proxy
|
||||
|
Loading…
x
Reference in New Issue
Block a user