apache - Python: Running multiple http requests concurrently based on an initial request? -


currently trying fetch api has 2 endpoints:

get /allusers  /user_detail/{id} 

in order details of users, have call get /allusers, , loop through ids call get /user_detail/{id} endpoint 1 1. wonder if it's possible have multiple get /user_detail/{id} calls running @ same time? or perhaps there better approach?

this sounds great use case grequests

import grequests  urls = [f'http://example.com/user_detail/{id}' id in range(10)]  rs = (grequests.get(u) u in urls) responses = grequests.map(rs) 

edit: example processing responses retrieve json could:

data = [] response in responses:     data.append(response.json()) 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -