[Python-ideas] How the heck does async/await work in Python 3.5

Ian Kelly ian.g.kelly at gmail.com
Wed Feb 24 11:47:41 EST 2016

On Wed, Feb 24, 2016 at 9:13 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Ian Kelly <ian.g.kelly at gmail.com>:
>> On Wed, Feb 24, 2016 at 8:23 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
>>> Tem Pl <rtempl31 at gmail.com>:
>>>> Is there something wrong with this implementation?
>>> It's a "fork bomb".
>> Isn't that the point of the benchmark?
> I don't quite see the point of the program as it doesn't resemble
> anything I'd ever have an urge to write.

That's reasonable. asyncio is designed for I/O-bound work, so a fair
response to the benchmark is that subjecting it to a CPU-bound stress
test is perhaps missing the point.

I was curious about how much the selector-based event loop might be
influencing the timing, so I tried instrumenting the selector.

class ProfiledSelector(selectors.DefaultSelector):
    def __init__(self):
        self._calls = collections.Counter()
    def select(self, timeout=None):
        self._calls['select'] += 1
        return super().select(timeout)
    def register(self, fileobj, events, data=None):
        self._calls['register'] += 1
        return super().register(fileobj, events, data)

selector = ProfiledSelector()
loop = asyncio.SelectorEventLoop(selector)
# 499999500000
# Counter({'select': 20, 'register': 1})

Only 20 iterations of the event loop? That doesn't seem unreasonable.

More information about the Python-list mailing list