-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Selector.select() hangs when there is nothing to select #69866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The following hangs on Linux >>> import selectors
>>> s = selectors.DefaultSelector()
>>> s.select() On Mac it returns an empty list. |
Your code doesn't make sense. You listen to 0 file descriptor and wait forever until you get events, which will never occur. I'm not even sure that it should be allowed by the Selector API. What's the point of your bug report? Does your application really rely on the behaviour of the selector when no file descriptor is registered? The behaviour changes between Linux and OS X because the "default" selector is a different selector on Linux (epoll) and OS X (kqueue? select?) |
To show surprising platform-dependent API behavior. I don't know what is the correct behavior here, but it should be cross platform. Seems like the most sane option is to throw an exception.
It was developed on Mac and relied (quite probably incorrectly) on the empty list result. When I run it on linux, it unexpectedly hanged. So, I would like to either
I think this special case should also be mentioned in the docs. |
I would expect it to hang (until the timeout expired) of no files are added. If it returns an empty list, that should mean the timeout expired. I guess Mac uses KqueueSelector. I would certainly expect SelectSelector to hang. Maybe the underlying kqueue implementation behaves differently though. Perhaps Python should handle this as a special case in the selectors module? |
Aleksey Kladov: "To show surprising platform-dependent API behavior." Hum ok, it makes sense :-) I agree that it would be better to have a portable behaviour in the selectors module which is supposed to be an abstraction providing a portable behaviour. We already wrote code to have the same behaviour when a file descriptor is closed (handle EBADF). Aleksey Kladov: "I think this special case should also be mentioned in the docs." I disagree, we can do better than documenting "bugs" :-) select.select([], [], [], None) raise an OSError "An invalid argument was supplied" on Windows. I propose to use this behaviour on all platforms for all selectors. I should be easy to write a patch in selectors, is anyone interested to write a patch? |
The result of Three platoforms made three different decisions in similar situation, so any behavior is reasonable and it should be made clear which one is used by Python. |
I don't think we should "fix" the select module; it's advertised as a wrapper around the various syscalls, and if the platforms disagree on what that syscall (e.g. select()) does we shouldn't try to fix it. (Documenting the differences is fine.) However the *selectors* module is a different thing. It defines a better abstraction that's supposedly independent from the underlying syscall. I agree with Aleksey that it should just hang when no FDs are registered and no timeout is given -- this is the only logical extension of its behavior when a FD is registered or a timeout is given. This could be used to wait until e.g. a signal arrives. It's illogical that it would behave differently if a FD was registered that will never fire, or if a timeout of a billion seconds was given (although that may be an easy hack to wait forever if the underlying syscall doesn't like this). The asyncio package would probably be broken because of this except that it always has a FD registered (the self-pipe). |
Looks like this is caused by bpo-29255 |
That may well be correct. Do you want to submit a PR to fix it? |
@gvanrossum PR is ready for review: #19508 |
I think this got auto-closed due to a link in the PR. Note that, per #19508 (comment), the behavior is still inconsistent on windows. I think the solution there will have to be a call to sleep() when the list of fds is empty. |
How ironic, the other issue had to be closed manually. :-) Reopening this one. |
I there still a difference between platforms here? Because then we should follow the recommendation of a previous comment. |
It sounds like Windows is still different, but GH-73442 is specifically open about that |
Okay, let's close, since the original issue is definitely solved. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: