Created
September 17, 2022 01:09
-
-
Save neelratanguria/47aad11e43f10f5bfcf83c86d7392040 to your computer and use it in GitHub Desktop.
Example for achieving concurrency in flask endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@signal_blueprint.route('/all-stats',) | |
async def signal_stats(): | |
tasks = [] | |
titles = [] | |
tasks.append(asyncio.gather(signal_actions.get_total_count())) | |
titles.append("signal_count") | |
tasks.append(asyncio.gather(spir_actions.get_total_signal_count())) | |
titles.append("spir_signal_count") | |
tasks.append(asyncio.gather(spir_actions.get_total_unseg_features_count())) | |
titles.append("spir_unseg_feats_count") | |
tasks.append(asyncio.gather(spir_actions.get_total_seg_signal_count())) | |
titles.append("spir_seg_sig_count") | |
tasks.append(asyncio.gather(spir_actions.get_total_cad_profile_count())) | |
titles.append("cad_profile_count") | |
results = await asyncio.gather(*tasks) | |
stats = {} | |
for indx, title in enumerate(titles): | |
stats[title] = results[indx] | |
return jsonify(success=True, message="Success", stats=stats), 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment