Description
Bug report
I think the selectors.KqueueSelector
, and selectors.PollSelector
behave differently in Mac OS X.
I tested the following code in Python 3.10.4, Mac OS X (12.5) Apple Sillicon.
Below is a simple code that creates a named pipe, opens two descriptors for read (non-block) and write(non-block).
I register a EVENT_READ
event on the read file descriptor, and write some message bytes to the pipe.
When the message is small (<8192 b), both Kqueue
and Poll
invokes a selector
event.
However, for large messages, Poll
works, but hangs with Kqueue
.
import os
import selectors
def test_should_return(selector: selectors.BaseSelector, msg: bytes):
pipe = "pipe.fifo"
os.mkfifo(pipe)
f1 = os.open(pipe, os.O_RDONLY | os.O_NONBLOCK)
f2 = os.open(pipe, os.O_WRONLY | os.O_NONBLOCK)
try:
selector.register(f1, selectors.EVENT_READ)
os.write(f2, msg)
assert selector.select() # should return as pipe can be read now
print("Passed!")
finally:
os.close(f1)
os.close(f2)
os.remove(pipe)
test_should_return(selectors.PollSelector(), b"m") # Passes
test_should_return(selectors.KqueueSelector(), b"m") # Passes
test_should_return(selectors.PollSelector(), b"m" * 10000) # Passes
test_should_return(selectors.KqueueSelector(), b"m" * 10000) # Hangs
I expected that for all four cases, the function should return normally (without the selector.select
function blocking). However, for Kqueue
selector and full-buffer writes to the named pipe leads to an infinite block.
Your environment
Python 3.10.4, Mac OS X (12.5) Apple Sillicon.