LazerSharks
LazerSharks

Reputation: 3155

Are most http requests synchronous by default?

Are most functions for http requests synchronous by default?

I came from Javascript and usage of AJAX and just started working with http requests in Python. To my surprise, it seems as though http request functions by default are synchronous, so I do not need to deal with any asynchronous behavior. For example, I'm working with the Requests http library, and although the docs don't explicitly say whether http requests are synchronous or not, by my own testing the calls seem to be synchronous.

So is it that most http requests are by default synchronous in nature, or most functions are designed that way? And my first experience with http requests (JS AJAX) just happened to be of an asynchronous nature?

Upvotes: 0

Views: 911

Answers (2)

Jaime Gomez
Jaime Gomez

Reputation: 7067

It's the language, in python most apis are synchronous by default, and the async version is usually an "advanced" topic. If you were using nodejs, they would be async; even if using javascript, the reason ajax is asynchronous is because of the nature of the browser.

Upvotes: 2

alecxe
alecxe

Reputation: 473853

requests is completely synchronous/blocking. grequests is what you are looking for:

GRequests allows you to use Requests with Gevent to make asynchronous HTTP Requests easily.

See also:

Upvotes: 1

Related Questions