Skip to main content
Made more concise, clear in my ramblings
Source Link
arshbot
  • 16.2k
  • 16
  • 51
  • 79

I have a lot of issues with most of the answers posted - they either use deprecated libraries that have been ported over with limited features, or provide a solution with too much magic on the execution of the request, making it difficult to error handle. If they do not fall into one of the above categories, they're 3rd party libraries or deprecated.

Some of the solutions works alright purely in http requests, but the solutions fall short for any other kind of request, which is ludicrous. A highly customized solution is not necessary here.

Simply using the python built-in library asyncio is sufficient enough to perform asynchronous requests of any type, as well as providing enough fluidity for complex and usecase specific error handling.

import asyncio loop = asyncio.get_event_loop() def do_thing(ch_idparams): async def get_chan_info_and_do_choresget_rpc_info_and_do_chores(ch_idid): # do things response = perform_grpc_call(ch_idid) do_chores(response) async def get_httpapi_info_and_do_chores(ch_idid):   # do things  response = requests.get(URL) do_chores(response) async_tasks = [] for ch_idelement in list(channelsparams.list_of_things): async_tasks.append(loop.create_task(get_chan_info_and_do_chores(ch_idid))) async_tasks.append(loop.create_task(get_httpapi_info_and_do_chores(ch_id))) loop.run_until_complete(asyncio.gather(*async_tasks)) 

How it works is simple. You're creating a series of tasks you'd like to occur asynchronously, and then asking a loop to execute those tasks and exit upon completion. No extra libraries subject to lack of maintenance, no lack of functionality required.

I have a lot of issues with most of the answers posted - they either use deprecated libraries that have been ported over with limited features, or provide a solution with too much magic on the execution of the request, making it difficult to error handle. If they do not fall into one of the above categories, they're 3rd party libraries or deprecated.

Some of the solutions works alright purely in http requests, but the solutions fall short for any other kind of request, which is ludicrous. A highly customized solution is not necessary here.

Simply using the python built-in library asyncio is sufficient enough to perform asynchronous requests of any type, as well as providing enough fluidity for complex and usecase specific error handling.

import asyncio loop = asyncio.get_event_loop() def do_thing(ch_id): async def get_chan_info_and_do_chores(ch_id): response = perform_grpc_call(ch_id) do_chores(response) async def get_httpapi_info_and_do_chores(ch_id): response = requests.get(URL) do_chores(response) async_tasks = [] for ch_id in list(channels): async_tasks.append(loop.create_task(get_chan_info_and_do_chores(ch_id))) async_tasks.append(loop.create_task(get_httpapi_info_and_do_chores(ch_id))) loop.run_until_complete(asyncio.gather(*async_tasks)) 

How it works is simple. You're creating a series of tasks you'd like to occur asynchronously, and then asking a loop to execute those tasks and exit upon completion. No extra libraries subject to lack of maintenance, no lack of functionality required.

I have a lot of issues with most of the answers posted - they either use deprecated libraries that have been ported over with limited features, or provide a solution with too much magic on the execution of the request, making it difficult to error handle. If they do not fall into one of the above categories, they're 3rd party libraries or deprecated.

Some of the solutions works alright purely in http requests, but the solutions fall short for any other kind of request, which is ludicrous. A highly customized solution is not necessary here.

Simply using the python built-in library asyncio is sufficient enough to perform asynchronous requests of any type, as well as providing enough fluidity for complex and usecase specific error handling.

import asyncio loop = asyncio.get_event_loop() def do_thing(params): async def get_rpc_info_and_do_chores(id): # do things response = perform_grpc_call(id) do_chores(response) async def get_httpapi_info_and_do_chores(id):   # do things  response = requests.get(URL) do_chores(response) async_tasks = [] for element in list(params.list_of_things): async_tasks.append(loop.create_task(get_chan_info_and_do_chores(id))) async_tasks.append(loop.create_task(get_httpapi_info_and_do_chores(ch_id))) loop.run_until_complete(asyncio.gather(*async_tasks)) 

How it works is simple. You're creating a series of tasks you'd like to occur asynchronously, and then asking a loop to execute those tasks and exit upon completion. No extra libraries subject to lack of maintenance, no lack of functionality required.

Made more concise, clear in my ramblings
Source Link
arshbot
  • 16.2k
  • 16
  • 51
  • 79

So many 3rd party libraries supported, and nearly all of them are deprecated/point elsewhere, or have severely limited functionality.

I have a lot of issues with most of the answers posted - they either use deprecated libraries that have been ported over with limited features, or provide a solution with too much magic on the execution of the request, making it difficult to error handle. If they do not fall into one of the above categories, they're 3rd party libraries or deprecated.

Some of the solutions works alright purely in http requests, but the solutions fall short for any other kind of request, which is ludicrous. A highly customized solution is not necessary here.

I believe simplySimply using the python built-in library asyncio wasis sufficient enough to perform asynchronous requests of any type, as well as providing enough fluidity for complex and usecase specific error handling.

import asyncio loop = asyncio.get_event_loop() def do_thing(ch_id): async def get_chan_info_and_do_chores(ch_id): response = perform_grpc_call(ch_id) do_chores(response) async def get_httpapi_info_and_do_chores(ch_id): response = requests.get(URL) do_chores(response) async_tasks = [] for ch_id in list(channels): async_tasks.append(loop.create_task(get_chan_info_and_do_chores(ch_id))) async_tasks.append(loop.create_task(get_httpapi_info_and_do_chores(ch_id))) loop.run_until_complete(asyncio.gather(*async_tasks)) 

How it works is simple. you're basicallyYou're creating a series of tasks you'd like to occur asynchronously, and then askasking a loop to execute those tasks and exit upon completion. No extra libraries subject to lack of maintenance, no lack of functionality required.

So many 3rd party libraries supported, and nearly all of them are deprecated/point elsewhere, or have severely limited functionality.

I have a lot of issues with most of the answers posted - they either use deprecated libraries that have been ported over with limited features, or provide a solution with too much magic on the execution of the request, making it difficult to error handle.

Some of the solutions works alright purely in http requests, but the solutions fall short for any other kind of request.

I believe simply using the python built-in library asyncio was sufficient enough to perform asynchronous requests of any type, as well as providing enough fluidity for complex and usecase specific error handling.

import asyncio loop = asyncio.get_event_loop() def do_thing(ch_id): async def get_chan_info_and_do_chores(ch_id): response = perform_grpc_call(ch_id) do_chores(response) async def get_httpapi_info_and_do_chores(ch_id): response = requests.get(URL) do_chores(response) async_tasks = [] for ch_id in list(channels): async_tasks.append(loop.create_task(get_chan_info_and_do_chores(ch_id))) async_tasks.append(loop.create_task(get_httpapi_info_and_do_chores(ch_id))) loop.run_until_complete(asyncio.gather(*async_tasks)) 

How it works is simple. you're basically creating a series of tasks you'd like to occur asynchronously, and then ask a loop to execute those tasks and exit upon completion. No extra libraries subject to lack of maintenance, no lack of functionality required.

I have a lot of issues with most of the answers posted - they either use deprecated libraries that have been ported over with limited features, or provide a solution with too much magic on the execution of the request, making it difficult to error handle. If they do not fall into one of the above categories, they're 3rd party libraries or deprecated.

Some of the solutions works alright purely in http requests, but the solutions fall short for any other kind of request, which is ludicrous. A highly customized solution is not necessary here.

Simply using the python built-in library asyncio is sufficient enough to perform asynchronous requests of any type, as well as providing enough fluidity for complex and usecase specific error handling.

import asyncio loop = asyncio.get_event_loop() def do_thing(ch_id): async def get_chan_info_and_do_chores(ch_id): response = perform_grpc_call(ch_id) do_chores(response) async def get_httpapi_info_and_do_chores(ch_id): response = requests.get(URL) do_chores(response) async_tasks = [] for ch_id in list(channels): async_tasks.append(loop.create_task(get_chan_info_and_do_chores(ch_id))) async_tasks.append(loop.create_task(get_httpapi_info_and_do_chores(ch_id))) loop.run_until_complete(asyncio.gather(*async_tasks)) 

How it works is simple. You're creating a series of tasks you'd like to occur asynchronously, and then asking a loop to execute those tasks and exit upon completion. No extra libraries subject to lack of maintenance, no lack of functionality required.

Source Link
arshbot
  • 16.2k
  • 16
  • 51
  • 79

So many 3rd party libraries supported, and nearly all of them are deprecated/point elsewhere, or have severely limited functionality.

I have a lot of issues with most of the answers posted - they either use deprecated libraries that have been ported over with limited features, or provide a solution with too much magic on the execution of the request, making it difficult to error handle.

Some of the solutions works alright purely in http requests, but the solutions fall short for any other kind of request.

I believe simply using the python built-in library asyncio was sufficient enough to perform asynchronous requests of any type, as well as providing enough fluidity for complex and usecase specific error handling.

import asyncio loop = asyncio.get_event_loop() def do_thing(ch_id): async def get_chan_info_and_do_chores(ch_id): response = perform_grpc_call(ch_id) do_chores(response) async def get_httpapi_info_and_do_chores(ch_id): response = requests.get(URL) do_chores(response) async_tasks = [] for ch_id in list(channels): async_tasks.append(loop.create_task(get_chan_info_and_do_chores(ch_id))) async_tasks.append(loop.create_task(get_httpapi_info_and_do_chores(ch_id))) loop.run_until_complete(asyncio.gather(*async_tasks)) 

How it works is simple. you're basically creating a series of tasks you'd like to occur asynchronously, and then ask a loop to execute those tasks and exit upon completion. No extra libraries subject to lack of maintenance, no lack of functionality required.