0

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?

LazerSharks
  • 3,089
  • 4
  • 42
  • 67
  • 1
    Depends on library. I would imagine that there are more asynchronous calls - but such is the nature of programming (and "happens-before"). Although some languages/runtimes *only* have asynchronous I/O. – user2864740 Jul 25 '14 at 01:10
  • 2
    There are lots of synchronous http libraries. There are lots of asynchronous ones, too. I'm not sure that anyone really knows which there are more of. – dano Jul 25 '14 at 01:12
  • @dano Ah, okay. I think that's a great answer actually, clears things up conceptually. – LazerSharks Jul 25 '14 at 01:27

2 Answers2

2

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.

Jaime Gómez
  • 6,961
  • 3
  • 40
  • 41
1

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:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Ah, yeah I've noticed that library but thought it seemed like it was "taking extra steps" to be asynchronous. Thanks for pointing me in that direction – LazerSharks Jul 25 '14 at 01:30