Skip to content

Instantly share code, notes, and snippets.

@neelratanguria
Created September 17, 2022 01:09
Show Gist options
  • Save neelratanguria/47aad11e43f10f5bfcf83c86d7392040 to your computer and use it in GitHub Desktop.
Save neelratanguria/47aad11e43f10f5bfcf83c86d7392040 to your computer and use it in GitHub Desktop.
Example for achieving concurrency in flask endpoint
@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