I want to send two asynchronous requests using grequests.send
with a short but exact delay (say 20 ms) between them. I only want to handle the responses after both requests have been sent.
Putting a time.sleep
between the two sends doesn't work because sleep
yields to the response handler for request 1 before request 2 has been sent, so request 2 is sent late.
grequests.send(req1, grequests.Pool(1))
time.sleep(delay)
grequests.send(req2, grequests.Pool(1)) # Request is sent late
How can I ensure the whole block above is run atomically to ensure as close as possible to the expected wait time between requests, without a busy wait?