Skip to content

Feature: switch from select.select to selectors - #691

Merged
penguinolog merged 1 commit into
urwid:masterfrom
penguinolog:feature_selectors
Dec 8, 2023
Merged

penguinolog merged 1 commit into
urwid:masterfrom
penguinolog:feature_selectors

Conversation

@penguinolog

Copy link
Copy Markdown
Collaborator
  • Use DefaultSelector as automatically selected most efficient.
  • Use context manager for not holding resources.
  • InterruptedError is handled by selector (and since python 3.5 by select.select, see PEP 475)
Checklist
  • I've ensured that similar functionality has not already been implemented
  • I've ensured that similar functionality has not earlier been proposed and declined
  • I've branched off the master or python-dual-support branch
  • I've merged fresh upstream into my branch recently
  • I've ran tox successfully in local environment
  • I've included docstrings and/or documentation and/or examples for my code (if this is a new feature)

@penguinolog penguinolog added the Feature Feature request/implementation label Dec 8, 2023
@coveralls

coveralls commented Dec 8, 2023 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 7140441898

  • 19 of 22 (86.36%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.08%) to 72.57%

Changes Missing Coverage Covered Lines Changed/Added Lines %
urwid/_raw_display_base.py 0 1 0.0%
urwid/event_loop/select_loop.py 15 17 88.24%
Files with Coverage Reduction New Missed Lines %
urwid/event_loop/select_loop.py 1 88.6%
Totals Coverage Status
Change from base Build 7140121673: 0.08%
Covered Lines: 7579
Relevant Lines: 10558

💛 - Coveralls

* Use `DefaultSelector` as automatically selected most efficient.
* Use context manager for not holding resources.
* `InterruptedError` is handled by selector
  (and since python 3.5 by `select.select`, see PEP 475)
timeout = 0.0
with selectors.DefaultSelector() as selector:
for fd, callback in self._watch_files.items():
selector.register(fd, selectors.EVENT_READ, callback)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use modern api and parse self._watch_files once in iteration

@penguinolog
penguinolog requested review from ulidtko and wardi December 8, 2023 11:29
for fd in ready:
self._watch_files[fd]()
for record in ready:
record.data()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we put callback here

@wardi wardi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduces line count and probably makes SelectEventLoop perform better on linux, so that's great. This doesn't help with pipes not being selectable on windows though, right? Do all apps that want to be cross-platform need to be written to use sockets?

@penguinolog

Copy link
Copy Markdown
Collaborator Author

reduces line count and probably makes SelectEventLoop perform better on linux, so that's great. This doesn't help with pipes not being selectable on windows though, right? Do all apps that want to be cross-platform need to be written to use sockets?

Unfortunately, yes - only sockets under windows or use some gevent-like approach.
Technically we can use primitives with exchange without select for some operations, it was proposed long time ago. It will be not global solution, but reduce pain

@penguinolog
penguinolog merged commit c21747f into urwid:master Dec 8, 2023
@penguinolog
penguinolog deleted the feature_selectors branch December 8, 2023 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Feature request/implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants