Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
635fca97
Commit
635fca97
authored
Jan 25, 2014
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20311: selectors: Add a resolution attribute to BaseSelector.
parent
2041859f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
1 deletion
+33
-1
Doc/library/selectors.rst
Doc/library/selectors.rst
+4
-0
Lib/selectors.py
Lib/selectors.py
+22
-1
Lib/test/test_selectors.py
Lib/test/test_selectors.py
+5
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/selectors.rst
View file @
635fca97
...
...
@@ -98,6 +98,10 @@ below:
:class:`BaseSelector` and its concrete implementations support the
:term:`context manager` protocol.
.. attribute:: resolution
Resolution of the selector in seconds.
.. method:: register(fileobj, events, data=None)
Register a file object for selection, monitoring it for I/O events.
...
...
Lib/selectors.py
View file @
635fca97
...
...
@@ -5,7 +5,7 @@ This module allows high-level and efficient I/O multiplexing, built upon the
"""
from
abc
import
ABCMeta
,
abstractmethod
from
abc
import
ABCMeta
,
abstractmethod
,
abstractproperty
from
collections
import
namedtuple
,
Mapping
import
functools
import
select
...
...
@@ -82,6 +82,11 @@ class BaseSelector(metaclass=ABCMeta):
performant implementation on the current platform.
"""
@
abstractproperty
def
resolution
(
self
):
"""Resolution of the selector in seconds"""
return
None
@
abstractmethod
def
register
(
self
,
fileobj
,
events
,
data
=
None
):
"""Register a file object.
...
...
@@ -283,6 +288,10 @@ class SelectSelector(_BaseSelectorImpl):
self
.
_readers
=
set
()
self
.
_writers
=
set
()
@
property
def
resolution
(
self
):
return
1e-6
def
register
(
self
,
fileobj
,
events
,
data
=
None
):
key
=
super
().
register
(
fileobj
,
events
,
data
)
if
events
&
EVENT_READ
:
...
...
@@ -335,6 +344,10 @@ if hasattr(select, 'poll'):
super
().
__init__
()
self
.
_poll
=
select
.
poll
()
@
property
def
resolution
(
self
):
return
1e-3
def
register
(
self
,
fileobj
,
events
,
data
=
None
):
key
=
super
().
register
(
fileobj
,
events
,
data
)
poll_events
=
0
...
...
@@ -385,6 +398,10 @@ if hasattr(select, 'epoll'):
super
().
__init__
()
self
.
_epoll
=
select
.
epoll
()
@
property
def
resolution
(
self
):
return
1e-3
def
fileno
(
self
):
return
self
.
_epoll
.
fileno
()
...
...
@@ -445,6 +462,10 @@ if hasattr(select, 'kqueue'):
super
().
__init__
()
self
.
_kqueue
=
select
.
kqueue
()
@
property
def
resolution
(
self
):
return
1e-9
def
fileno
(
self
):
return
self
.
_kqueue
.
fileno
()
...
...
Lib/test/test_selectors.py
View file @
635fca97
...
...
@@ -363,6 +363,11 @@ class BaseSelectorTestCase(unittest.TestCase):
self
.
assertFalse
(
s
.
select
(
2
))
self
.
assertLess
(
time
()
-
t
,
2.5
)
def
test_resolution
(
self
):
s
=
self
.
SELECTOR
()
self
.
assertIsInstance
(
s
.
resolution
,
(
int
,
float
))
self
.
assertGreater
(
s
.
resolution
,
0.0
)
class
ScalableSelectorMixIn
:
...
...
Misc/NEWS
View file @
635fca97
...
...
@@ -36,6 +36,8 @@ Core and Builtins
Library
-------
- Issue #20311: selectors: Add a resolution attribute to BaseSelector.
- Issue #20189: unittest.mock now no longer assumes that any object for
which it could get an inspect.Signature is a callable written in Python.
Fix courtesy of Michael Foord.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment