KqueueSelector doesn't sleep when no files are passed


#1

Hi, I’m working on a test system which will either be based on curio or at least inspired by it.

Under OSX I’ve noticed that when KqueueSelector isn’t given any files it returns immediately. The result is that code such as this:

from curio import run, sleep

async def just_sleep():
    await sleep(20)

run(just_sleep())

uses 100% CPU whilst it’s running. Passing selector=SelectSelector() to run() ‘fixes’ this.

I think I’d argue that this is a bug, possibly in selectors, but I’m not sure. I’d be very interested to hear opinions on this.


#2

Interesting. I agree that this sounds like a bug in selectors.
SelectSelector on Windows has a similar problem. See:
https://github.com/dabeaz/curio/issues/75

My suspicion is that what’s going on here is that ‘selectors’ was written
for asyncio and hasn’t really been tested otherwise, and it turns out that
asyncio always has at least one file descriptor that it selects on, so no
one ever noticed all these bugs in the zero-file-descriptor cases :frowning:


#3

Interesting. I will need to check into this.