https://pulumi.com logo
Title
b

big-glass-16858

05/10/2019, 1:51 PM
I'm running Python 3.7.3 and the error is the following
RuntimeError: asyncio.run() cannot be called from a running event loop
if anyone can point me to the right docs or code, that would be nice 👍
b

big-piano-35669

05/11/2019, 2:39 AM
This typically happens when a promise is consumed from a different async event loop from the one it was allocated on. Pulumi uses promises internally and will try to consume the promise generated by
asyncio.run(get_availability_zones())
. Can you try it without the
asyncio.run
? This should still return a promise, but the call to
get_availability_zones
already allocates it on the event loop Pulumi is using. So the
asyncio.run
shouldn't be necessary, unless I'm missing something.
b

big-glass-16858

05/11/2019, 8:26 AM
Hi Joe, Thanks for taking time to answer, it does return a promise when calling directly
get_availability_zone()
(actually it's a
coroutine
) , we have to resolve it by calling
await
but this can only be done in a
async
function, and
__init__
in python can't be async. I resolved this issue by creating a new event loop and resolving the promise there. I'm not a python expert but other techniques I've seen involve creating a factory to actually create the object, I choose the separated event loop because I think it is actually more understandable and easy to use for other devs. Thank you.