Comments (2)
If you want to disable gevent.monkey.patch_all()
in grequests
(without forking), this should work:
import mock # unittest.mock in Python 3.3+
with mock.patch('gevent.monkey.patch_all', lambda *args, **kwargs: None):
import grequests
It is best if gevent.monkey.patch_all()
is only done in application entrypoints, not libraries, because it should be done before all other imports, and should only be done once. From the gevent documentation:
Patching should be done as early as possible in the lifecycle of the program. For example, the main module (the one that tests against main or is otherwise the first imported) should begin with this code, ideally before any other imports
Even if you can't control where import grequests
is done, doing the above mock.patch()
in your application entrypoint should work, because Python should only import grequests
once. Once it is imported that version keeps getting used, and import-time side effects of grequests
shouldn't get run again.
from grequests.
Hi @belingud
Thanks for submitting this well-thought out issue. Using grequests
together with other applications, particularly ones that also use gevent
is often a source of pain when using this project. In general, we don't recommend using grequests
together with such other packages and we recommend use of grequests
be, more or less, standalone.
Nevertheless, such use cases seem to arise commonly.
There's a few things the stand between the current situation and a, perhaps, more desirable state. There's maybe also some alternative ways that grequests
can use monkey patching to make things easier for other applications.
One suggestion has been to make the monkey patching in grequests less aggressive. I'm not sure, however, which components need to be patched by grequests. But if we could limit the patching to exactly what grequests needs, that may make it more compatible with other applications.
SInce the patch happens on import, I'm not sure what the best way would be to give users control of the monkey patch would be. I'll think some more on this. But at the end of the day, grequests does need certain things patched and may not even work correctly without those patches, which may mean that, ultimately, grequests is inherently incompatible with certain applications.
In the meantime, @belingud it is perhaps useful to know that grequests is composed of just a single file. You could try copying grequests directly to your own project (instead of installing it via pip) and modify the monkeypatching to see what may work for you! It will be useful to know, for example, whether grequests works without patching thread
from grequests.
Related Issues (20)
- Grequests is creating Recursion errors due to invalid monkey patch HOT 3
- response is None HOT 4
- Grequest returns empty generators HOT 2
- How to convert response for a json HOT 1
- limit number of requests per second. HOT 1
- why size is no affect in map? HOT 1
- Add index in imap HOT 3
- Params of get/post functions HOT 3
- Import fails HOT 1
- Grequests warning and crash HOT 3
- Docker crash HOT 2
- Request for image HOT 2
- Append wait time or rate for every thread due to server limits HOT 1
- Python 3.6 the fastest environment?
- Python 3.6 the fastest environment? HOT 2
- gtimeout does not works with imap_enumerated HOT 1
- Flag to print the request being executed HOT 2
- How to ignore SSL cert verification failed in grequests? HOT 2
- grequests.map() is slow when passing requests with the data parameter HOT 2
- nose should be in `dev_requirements.txt`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grequests.