Comments (1)
@Koushikphy there is no builtin option for this. However, grequests
is just a thin wrapper around requests
, so solutions that work for requests
should be adaptable for grequests
.
For example, if you implement a subclass of requests.Session
that obeys rate limiting, you could pass that to the session
keyword parameter. There are likely many existing packages in the ecosystem that already provide something like this.
As a simple example:
import grequests
import requests
from gevent.time import sleep
class RateLimitedSession(requests.Session):
def should_wait_for_rate_limit(self, request) -> bool:
print('implement your rate limiting logic here')
return True
def send(self, request, **kwargs):
while True:
if self.should_wait_for_rate_limit(request):
print('waiting for rate limit for request', request.url)
sleep(0.1)
else:
print('sending request for', request.url)
return super().send(request, **kwargs)
session = RateLimitedSession()
req_list = [grequests.get('https://httpbin.org/status/200', session=session) for _ in range(20)]
for resp in grequests.imap(req_list, size=10):
print('resp:', resp)
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
- 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.