Has anyone managed to get async calls working insi...
# python
f
Has anyone managed to get async calls working inside a dynamic resource provider? I need to make a few HTTP calls, but can't quite sort out the magic to get Pulumi to work with them.
r
Can you say more about what isn’t working as you expect? Perhaps with code samples?
f
I may be doing something wrong, as I've not had occasion to do async Python before, but it seems like I'd need something like this:
Copy code
async def create(self, inputs):
    let x = await make_an_http_request(...)
    # do stuff with x
    return CreateResult(...)
but I get
RuntimeWarning: coroutine 'create' was never awaited
r
You can make API calls in python without using async/await. Generally async/await is not used unless you are specifically using a library that uses asyncio.
You probably want to use something like requests which doesn’t use asyncio and just immediately awaits the output of the api call.
That being said if you do need to use an asyncio library, you’ll need to make sure that all asynchronous tasks are resolved within the
create
function, because that function itself cannot be
async
. So you’ll probably need to do something like:
Copy code
def create(self, inputs):
    x = asyncio.run(make_an_http_request(...))
    return CreateResult(...)
if
make_an_http_request
returns an Awaitable
f
Ah, I see; thanks!