python - How select.select() works?
Python's select()
gets passed through as a select()
system call as you are expecting, but the problem you have with it blocking is a different issue, probably relating to buffering. Just to satify yourself that select()
is doing the right thing, try reading/writing a file on the file system rather than using a special device such as a joystick.
You probably want to change your open()
call. Pythons open
call will by default use buffered reads, so even if you do a read(8)
it will likely read more data from the input file and buffer the results. You need to set the buffering
option to open
so that the joystick device is opened unbuffered.
Suggestions for you to try:
- Python defaults to opening files in text mode. You probably want the open
mode
to berb
when dealing with special devices such as a joystick. - Open file in unbuffered mode.
- Set the device into non-blocking mode if you're going to be doing
select
based calls. Try usingos.open()
withos.O_RDONLY|os.O_NONBLOCK
flags.
Can I ask a stupid question - are you sure there are really 8 bytes left?
Device nodes don't necessarily behave like normal files. It might be that you have to read the entire struct input_event in a single read() system call. (And if you don't read enough, the rest gets thrown away). A bit like recvmsg() on datagram sockets.