diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-25 13:56:48 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-25 13:56:48 (GMT) |
commit | 635fca9704b102a97233a3af18231a7b649d0169 (patch) | |
tree | 581707f774cffe719a80b08297f0bb9ce5eb342c /Lib | |
parent | 2041859f279423c06a707899b4a66e3f0aba3dfb (diff) | |
download | cpython-635fca9704b102a97233a3af18231a7b649d0169.zip cpython-635fca9704b102a97233a3af18231a7b649d0169.tar.gz cpython-635fca9704b102a97233a3af18231a7b649d0169.tar.bz2 |
Issue #20311: selectors: Add a resolution attribute to BaseSelector.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/selectors.py | 23 | ||||
-rw-r--r-- | Lib/test/test_selectors.py | 5 |
2 files changed, 27 insertions, 1 deletions
diff --git a/Lib/selectors.py b/Lib/selectors.py index cd8b29e..b1b530a 100644 --- a/Lib/selectors.py +++ b/Lib/selectors.py @@ -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() diff --git a/Lib/test/test_selectors.py b/Lib/test/test_selectors.py index 5292904..f7e84b7 100644 --- a/Lib/test/test_selectors.py +++ b/Lib/test/test_selectors.py @@ -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: |