Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use grequests in Flask with strange error #99

Closed
pengyusong opened this issue Nov 23, 2016 · 1 comment
Closed

use grequests in Flask with strange error #99

pengyusong opened this issue Nov 23, 2016 · 1 comment
Labels
🙉🙈🙊 gevent some issue likely caused by gevent, not necessarily grequests

Comments

@pengyusong
Copy link

pengyusong commented Nov 23, 2016

i‘ import grequests in flask blueprints, because i want send multi requests in one http request of flask. but i encountered a problem:

eventpoll fd will be increased for every http request, even if the http request does not use grequests.

I use ‘strace -p’ to get something deeply:

Compared with normal case, it add two ‘fcntl ‘ system call, they change the socket type to O_NONBLOCK.

it shows as follows:
accept(3, {sa_family=AF_INET, sin_port=htons(58226), sin_addr=inet_addr("192.168.1.14")}, [16]) = 9 fcntl(9, F_GETFL) = 0x2 (flags O_RDWR) fcntl(9, F_SETFL, O_RDWR|O_NONBLOCK) = 0

Notice:
i use werkzeug server to start flask will raise up this problem, if i use uwsgi etc. the problem will not occur.

questions:

  1. dose grequests lib will infect outside socket(flask) ?
  2. if above answer is true, how to avoid it?
@spyoungtech
Copy link
Owner

spyoungtech commented Dec 23, 2017

Because of the monkey-patching, importing grequests does end up potentially touching, and potentially breaking lot of other libraries. There are a number of other related issues that have been opened in the same light. Perhaps one of those may contain a clue to a possible solution. It would likely take a lot of effort to get down to the bottom of the cause, let alone a solution.

In my experience grequests works great in many cases. But if it doesn't work for your particular case, you may want to consider using, as the README now suggests, requests-threads or requests-futures instead.

Closing this for now. If you can provide some more details or other discoveries, we can reopen.

@spyoungtech spyoungtech added the 🙉🙈🙊 gevent some issue likely caused by gevent, not necessarily grequests label Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙉🙈🙊 gevent some issue likely caused by gevent, not necessarily grequests
Projects
None yet
Development

No branches or pull requests

2 participants