1--------------------------------------------------------------
2Timeout function
3--------------------------------------------------------------
4import asyncio
5from async_timeout import timeout
6
7class Student:
8 def __init__(self):
9 self.queue = asyncio.Queue()
10 pass
11
12 async def function(self):
13 try:
14 async with timeout(300): # 5 minutes...
15 #source = await self.queue.get()
16
17 #do what u need to do
18 pass
19
20 except asyncio.TimeoutError as e:
21 print(e)
22
23
24--------------------------------------------------------------
25Requests
26--------------------------------------------------------------
27import requests as r
28
29class Student:
30 def __init__(self):
31 pass
32
33 def function(url:string):
34 try:
35 data = r.get(url, timeout=10.0)
36 except requests.Timeout as err:
37 logger.error({"message": err.message})
38 except Exception as err:
39 print(err)
40 return data # or what ever u need to return
41
42
43