In Bash, it is possible to execute a command in the background by appending &
. How can I do it in Python?
while True: data = raw_input('Enter something: ') requests.post(url, data=data) # Don't wait for it to finish. print('Sending POST request...') # This should appear immediately.
The requests. get function is a blocking call. It will wait until the response arrives before the rest of your program will execute.
Use Python's synchronous, multi-threading, queue, and asyncio event loop to make 100 HTTP requests and see which solution performs the best. It is easy to send a single HTTP request by using the requests package.
What is the default timeout for Python requests? None. There is no default timeout for Python requests, unless explicitly set using the timeout parameter.
Like urllib2 , requests is blocking. But I wouldn't suggest using another library, either. The simplest answer is to run each request in a separate thread. Unless you have hundreds of them, this should be fine.
Here's a hacky way to do it:
try: requests.get("http://127.0.0.1:8000/test/",timeout=0.0000000001) except requests.exceptions.ReadTimeout: pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With