Berker Peksag added the comment:
+ .. method:: get_map()
+
+ Return a mapping of file objects to selector keys.
I kind of feel like a walking linter though I think this needs a versionadded
tag :)
--
keywords: -needs review
nosy: +berker.peksag
Charles-François Natali added the comment:
Berker Peksag added the comment:
+ .. method:: get_map()
+
+ Return a mapping of file objects to selector keys.
I kind of feel like a walking linter though I think this needs a versionadded
tag :)
Well, selectors have been added to 3.4
Guido van Rossum added the comment:
LGTM. Commit!
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19172
___
___
Python-bugs-list mailing list
Guido van Rossum added the comment:
(Adding CF's new patch so I can compare and review it.)
--
Added file: http://bugs.python.org/file32428/selectors_map-2.patch
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19172
Roundup Robot added the comment:
New changeset b0ae96700301 by Charles-François Natali in branch 'default':
Issue #19172: Add a get_map() method to selectors.
http://hg.python.org/cpython/rev/b0ae96700301
--
nosy: +python-dev
___
Python tracker
Charles-François Natali added the comment:
Committed.
Antoine, thanks for the idea and patch!
--
resolution: - fixed
stage: patch review - committed/rejected
status: open - closed
___
Python tracker rep...@bugs.python.org
Guido van Rossum added the comment:
I added some comments to the code review. Please take a look.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19172
___
Charles-François Natali added the comment:
Antoine Pitrou added the comment:
FWIW, I think the ideal solution would be for keys() (*) to return a
read-only Mapping implementation, allowing for file object lookup (using
__getitem__) as well as iteration on SelectorKeys (using __iter__) and
STINNER Victor added the comment:
BaseSelector.register(fd) raises a KeyError if fd is already registered, which
means that any selector must know the list of all registered FDs. For
EpollSelector, the list may be inconsistent *if* the epoll is object is
modified externally, but it's really a
Charles-François Natali added the comment:
BaseSelector.register(fd) raises a KeyError if fd is already registered,
which means that any selector must know the list of all registered FDs. For
EpollSelector, the list may be inconsistent *if* the epoll is object is
modified externally, but
STINNER Victor added the comment:
2013/10/6 Charles-François Natali rep...@bugs.python.org:
BaseSelector.register(fd) raises a KeyError if fd is already registered,
which means that any selector must know the list of all registered FDs. For
EpollSelector, the list may be inconsistent *if*
Guido van Rossum added the comment:
No time to follow this in detail, but one thing: please do not make the
selector appear false under *any* circumstances. I've seen too many code
write if foo where they meant if foo is not None and get in trouble because
foo wasn't None but happened to have
STINNER Victor added the comment:
Perhaps the method shouldn't be called keys() to avoid any confusion with
subclasses of the Container ABC?
If you don't want to rename the SelectorKey class, rename the method
to get_keys().
--
___
Python tracker
Antoine Pitrou added the comment:
FWIW, I think the ideal solution would be for keys() (*) to return a
read-only Mapping implementation, allowing for file object lookup (using
__getitem__) as well as iteration on SelectorKeys (using __iter__) and
fast emptiness checking (using __len__).
Antoine Pitrou added the comment:
FWIW, I think the ideal solution would be for keys() (*) to return a
read-only Mapping implementation, allowing for file object lookup (using
__getitem__) as well as iteration on SelectorKeys (using __iter__) and
fast emptiness checking (using __len__).
(to
Antoine Pitrou added the comment:
Here is a proof-of-concept patch adding a get_map() method to Selector (and
removing get_key()).
--
Added file: http://bugs.python.org/file31977/selectors_map.patch
___
Python tracker rep...@bugs.python.org
New submission from Charles-François Natali:
This adds a keys() method to selectors, to return all the registered keys.
It's useful, because one often needs to loop until all registered file objects
have been unregistered e.g. (inspired from subprocess, see #18923):
while selector.keys():
STINNER Victor added the comment:
If you want to unregister while iterating on .keys(), just copy .keys(), as
I do when removing items from a list or a dict while iterating on it.
--
___
Python tracker rep...@bugs.python.org
Antoine Pitrou added the comment:
Indeed it's easy enough to call list() or set() on the result if you need it.
On the other hand, the problem with returning a dict view is that it makes the
return type dependent on an implementation detail. Returning a simple iterator
would be great, except
STINNER Victor added the comment:
Using .keys() to test if the selector is empty is surprising. To test if a
str, list, tuple, dict, set, ..., is empty: if container: not empty is
enough.
Or sometimes I write if len(container): ...
Selector has no length?
--
Charles-François Natali added the comment:
If you want to unregister while iterating on .keys(), just copy .keys(), as
I do when removing items from a list or a dict while iterating on it.
Of course, but as noted by Antoine, it makes the return type dependent of an
implementation detail (I
21 matches
Mail list logo