Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can or How to use Python asyncio on Google Cloud Functions?

Is it possible to use Python's asyncio on Google Cloud Functions?

async def handle_someting():
    # do something
    some = await aiofunc()

# Do I need the code below?
loop = asyncio.get_event_loop()
loop.run_until_complete(handle_someting())
loop.close()
like image 904
Sagnol Avatar asked Oct 11 '18 08:10

Sagnol


Video Answer


1 Answers

Sure, you just need to run the async functions from your main deployed function (here, you would deploy the test function):

import asyncio

async def foo():
    return 'Asynchronicity!'

async def bar():
    return await foo()

def test(request):
    return asyncio.run(bar())
like image 150
Dustin Ingram Avatar answered Sep 22 '22 01:09

Dustin Ingram