forked from runpod/runpod-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall_endpoint_asyncio.py
More file actions
38 lines (27 loc) · 817 Bytes
/
call_endpoint_asyncio.py
File metadata and controls
38 lines (27 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Example of calling an endpoint using asyncio.
"""
import asyncio
import aiohttp
import runpod
from runpod import AsyncioEndpoint, AsyncioJob
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # For Windows Users
runpod.api_key = "YOUR_API_KEY"
async def main():
'''
Function to run the example.
'''
async with aiohttp.ClientSession() as session:
# Invoke API
payload = {}
endpoint = AsyncioEndpoint("ENDPOINT_ID", session)
job: AsyncioJob = await endpoint.run(payload)
# Get current job status
status = await job.status()
# Print status
print(status)
# Wait until job is completed or failed
output = await job.output()
# Print output
print(output)
asyncio.run(main())