question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ascync non-blocking?

See original GitHub issue

Is it possible to initialize a pool to return the result but continue the code execution like so?

import grequests

def print_res(res, *args, **kwargs):
    from pprint import pprint
    pprint (vars(res))

print 'starting grequest'

req = grequests.post('http://www.cricket.com.au/', hooks=dict(response=print_res))
job = grequests.send(req, grequests.Pool(1))

print 'request made'

for i in range(10):
    print i

So that would show the request was made but still print the range while the request was in process and then finally print out the results of the send?

I’d really love to use grequests but the examples/documentation are fairly sparse so I’m struggling.

Thanks for any help.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8

github_iconTop GitHub Comments

11reactions
RavisMskcommented, Apr 21, 2016

@jakehilton

Hey Jake,

This library is blocking calling thread, so it’s not as asynchronous as you could think. It’s like half-asynchronous, dunno how to call that… I think lots of people actually think it’ll send the HTTP task to separate thread-pool and eventually call back with results, but it doesn’t. Yes, it sends multiple requests, which are asynchronous TO EACH OTHER, and awaits them (https://github.com/kennethreitz/grequests/blob/master/grequests.py#L117). And that is really confusing. I think authors should clarify that in docs.

0reactions
kennethreitzcommented, Mar 8, 2018

From the readme: Note: You should probably use requests-threads or requests-futures instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

asynchronous and non-blocking calls? also between ...
Asynchronous program: A program which uses Non blocking calls. It can have only 1 thread and still remain interactive. Share.
Read more >
The difference between asynchronous and non-blocking
Asynchronous and non-blocking I/O are the opposites of synchronous and blocking. In a sense both are fairly similar in that they allow your...
Read more >
Overview of Blocking vs Non-Blocking
Choosing non-blocking asynchronous operations frees up that 45ms per request to handle other requests. This is a significant difference in capacity just by ......
Read more >
How Java Is Used for Asynchronous Non-blocking ...
In this article, the author explains several methods used for asynchronous non-blocking programming in Java.
Read more >
Blocking and Non-Blocking in Node.js
Non -Blocking: It refers to the program that does not block the execution of further operations. Non-Blocking methods are executed asynchronously ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found