Skip to content

Tag: python-asyncio

async exec in python

I’d like to call exec in an async function and do something like the following code (which is not valid): More precisely, I’d like to be able to wait for a future inside the code that runs in exec. How can this be achieved? Answer Note: F-strings are only supported in python 3.6+. For older versio…

Semantic equivalent of async for

From the docs relative to async for syntax in Python 3.5, I gathered that it was introduced to iterate over an awaitable iterator. There is something I don’t get in the semantic equivalent that follow the description though: What is the line iter = type(iter).__aiter__(iter) doing? Why is it necessary? …

Mocking async call in python 3.5

How do I mock async call from one native coroutine to other one using unittest.mock.patch? I currently have quite an awkward solution: Then This works but looks ugly. Is there more pythonic way to do this? Answer The solution was actually quite simple: I just needed to convert __call__ method of mock into cor…