Skip to content
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

Feature: switch from select.select to selectors #691

Merged
merged 1 commit into from Dec 8, 2023

Conversation

penguinolog
Copy link
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
Copy link

coveralls commented Dec 8, 2023

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
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

for fd in ready:
self._watch_files[fd]()
for record in ready:
record.data()
Copy link
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

Copy link
Collaborator

@wardi wardi left a comment

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
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
35 checks passed
@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.

None yet

3 participants