2021年3月4日星期四

How to use Python asyncio on Google Cloud Functions?

I have a google cloud function triggered by HTTP request does following two tasks:

def task1():    do sth    return info    def task2(info):    do sth      def main(request)    info=task1()    if (info):      task2(info)    return info  

I would like the function returns without waiting the task2 completes. So I did following changes:

import asyncio    def task1():    do sth    return info    async def task2(info):    do sth    async def bar(info):    return await task2(info)      def main(request)    info=task1()    if (info):      asyncio.run(bar(info))    return info  

Not sure if I did is correct? But I didn't notice the function gets any faster. Can anyone give me some suggestions?

https://stackoverflow.com/questions/66484552/how-to-use-python-asyncio-on-google-cloud-functions March 05, 2021 at 07:26AM

没有评论:

发表评论