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.