-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-44951: Allow setting EPOLLEXCLUSIVE on selectors.EpollSelector #27819
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,15 +348,16 @@ def __init__(self): | |
super().__init__() | ||
self._selector = self._selector_cls() | ||
|
||
def register(self, fileobj, events, data=None): | ||
def register(self, fileobj, events, data=None, register_flags=None): | ||
key = super().register(fileobj, events, data) | ||
poller_events = 0 | ||
if register_flags is None: | ||
register_flags = 0 | ||
if events & EVENT_READ: | ||
poller_events |= self._EVENT_READ | ||
register_flags |= self._EVENT_READ | ||
if events & EVENT_WRITE: | ||
poller_events |= self._EVENT_WRITE | ||
register_flags |= self._EVENT_WRITE | ||
try: | ||
self._selector.register(key.fd, poller_events) | ||
self._selector.register(key.fd, register_flags) | ||
except: | ||
super().unregister(fileobj) | ||
raise | ||
|
@@ -445,6 +446,29 @@ class EpollSelector(_PollLikeSelector): | |
_EVENT_READ = select.EPOLLIN | ||
_EVENT_WRITE = select.EPOLLOUT | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self._exclusive = False | ||
|
||
@property | ||
def exclusive(self): | ||
return self._exclusive | ||
|
||
def set_exclusive(self, value): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far Since we already have |
||
if not isinstance(value, bool): | ||
raise ValueError("Not a boolean") | ||
if not hasattr(select, "EPOLLEXCLUSIVE"): | ||
raise ValueError("Python was not compiled " | ||
"with EPOLLEXCLUSIVE") | ||
self._exclusive = value | ||
|
||
def register(self, fileobj, events, data=None): | ||
register_flags = 0 | ||
if self._exclusive: | ||
register_flags |= select.EPOLLEXCLUSIVE | ||
return super().register(fileobj, events, | ||
data=data, register_flags=register_flags) | ||
|
||
def fileno(self): | ||
return self._selector.fileno() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
:func:`selectors.EpollSelector.set_exclusive` added to enable setting *EPOLLEXCLUSIVE* automatically on polled file descriptors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is in a method literally called
register
, I'd name the new argument simplyflags
.