Regarding return value of python select.select call
In python's SocketServer.py code, I find the following code.
r, w, e = _eintr_retry(select.select, [self], [], [], poll_interval)
if self in r:
self._handle_request_noblock()
Is the above if statement necessary? Since only "self" is being passed to select call, I do not expect other file descriptor to be present in the returned list of file descriptor.
The reason I am asking this is, should I have to follow the above style or something like the following would be enough?
r, w, e = select.select( [self], [], [], poll_interval)
if r:
...
if r:
is not the same as
if self in r:
You can read on select.select
documentation:
Empty sequences are allowed, but acceptance of three empty sequences is platform-dependent.
[...]
The return value is a triple of lists of objects that are ready: subsets of the first three arguments. When the time-out is reached without a file descriptor becoming ready, three empty lists are returned .
Since, in the module, a variable poll_interval
is being passed to the function, you may get a case when empty lists are returned. An empty list will pass the simple if r:
check!
上一篇: 你如何用一行来包装一个命令?