Skip to content

Commit ef897ee

Browse files
committed
Support APIClient when use async with context
1 parent dab3c4a commit ef897ee

7 files changed

+30
-1
lines changed

dist/tikhub-1.11.8-py3-none-any.whl

-64.5 KB
Binary file not shown.

dist/tikhub-1.11.8.tar.gz

-43.3 KB
Binary file not shown.

dist/tikhub-1.11.9.tar.gz

-43.9 KB
Binary file not shown.

dist/tikhub-1.12.2.tar.gz

46 KB
Binary file not shown.

tikhub/client/client.py

+29
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,35 @@ def __init__(self,
129129
# Hybrid Parsing
130130
self.HybridParsing = HybridParsing(self.client)
131131

132+
"""
133+
[中文]
134+
135+
这些代码用于实现异步上下文管理器,使得类的实例可以与 async with 语句一起使用,从而在进入和退出时自动处理资源的初始化和清理。
136+
137+
例如:
138+
async with Client(api_key=api_key) as client:
139+
pass
140+
141+
这样在退出时会自动调用 __aexit__ 方法,关闭 client。
142+
143+
[English]
144+
145+
This code is used to implement an asynchronous context manager,
146+
which allows instances of a class to be used with the async with statement,
147+
automatically handling the initialization and cleanup of resources when entering and exiting.
148+
149+
For example:
150+
async with Client(api_key=api_key) as client:
151+
pass
152+
153+
This way, the __aexit__ method is automatically called when exiting, closing the client.
154+
"""
155+
async def __aenter__(self):
156+
return self
157+
158+
async def __aexit__(self, exc_type, exc_val, exc_tb):
159+
await self.client.close()
160+
132161

133162
if __name__ == '__main__':
134163
# Example

tikhub/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# tikhub/version.py
2-
version = "1.12.1"
2+
version = "1.12.2"

0 commit comments

Comments
 (0)