Does python block httplib.HTTPConnection?

I am not sure if the following code is a blocking operation in python:

import httplib
import urllib

def do_request(server, port, timeout, remote_url):
    conn = httplib.HTTPConnection(server, port, timeout=timeout)
    conn.request("POST", remote_url, urllib.urlencode(query_dictionary, True))
    conn.close()
    return True

do_request("http://www.example.org", 80, 30, "foo/bar")
print "hi!"

And if so, how could one create a non-blocking asynchronous HTTP request in python?

Thanks from python noob.

+3
source share
1 answer

If you do not get to the length to prevent it, IOit will always be blocked.

Although you can perform asynchronous requests , you will need to make your program non-asynchronous. Async does not magically make your code non-blocking . It would be much easier to execute the request in another thread or process if you do not want to block the main loop.

, Twisted.

+5

Source: https://habr.com/ru/post/1739799/


All Articles