Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python timeout exception

--------------------------------------------------------------
Timeout function
--------------------------------------------------------------
import asyncio
from async_timeout import timeout

class Student:
  	def __init__(self):
      	self.queue = asyncio.Queue()
      	pass
  	
	async def function(self):
      	try:
    		async with timeout(300): # 5 minutes...
              	#source = await self.queue.get()
            	
                #do what u need to do
                pass
                
        except asyncio.TimeoutError as e:
        	print(e)
            
            
--------------------------------------------------------------
Requests
--------------------------------------------------------------
import requests as r

class Student:
	def __init__(self):
      	pass
      
  	def function(url:string):
		try:
    		data = r.get(url, timeout=10.0)
		except requests.Timeout as err:
    		logger.error({"message": err.message})
		except Exception as err:
          	print(err)
        return data # or what ever u need to return

      
      
Comment

PREVIOUS NEXT
Code Example
Python :: python count how many times a character appears in a string 
Python :: merge lists 
Python :: Program to Compute LCM 
Python :: getenv python 
Python :: fibonacci sequence in python 
Python :: tqdm in place 
Python :: install glob module in linux 
Python :: subtract list from list python 
Python :: how to pause a python script 
Python :: select python 
Python :: to string python 
Python :: Python NumPy broadcast_arrays() Function Example 
Python :: python cut string to length 
Python :: Python Tkinter Button Widget 
Python :: kpss test python 
Python :: split string into groups of 3 chars python 
Python :: counter +1 python 
Python :: how to convert numpy array to cv2 image 
Python :: hashmap python 
Python :: python switch case 3.10 Structural Pattern Matching 
Python :: send mail through python 
Python :: pandas read excel certain columns 
Python :: dm user discord.py 
Python :: plotly color specific color 
Python :: how to convert datetime to integer in python 
Python :: numpy sqrt 
Python :: bar plot group by pandas 
Python :: compare times python 
Python :: count repeated strings map python 
Python :: python how to play mp3 file 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =