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!

链接地址: http://www.djcxy.com/p/9660.html

上一篇: 你如何用一行来包装一个命令?

下一篇: 关于python select.select调用的返回值