Implementation of `select.poll` on Microsoft Windows.
Project description
Implementation of select.poll on Microsoft Windows.
- Pure Python; no C extensions (uses
ctypes.windll.Ws2_32) - Drop-in-compatible API
- Clean "ponyfill"; library does no monkeypatching
- Python 3.7+ compatible
- No dependencies
Usage
Alternative to select.poll
try:
from select import (
POLLIN, POLLOUT, POLLERR, POLLHUP, POLLNVAL,
poll
)
except ImportError:
# https://github.com/python/cpython/issues/60711
from winpoll import (
POLLIN, POLLOUT, POLLERR, POLLHUP, POLLNVAL,
wsapoll as poll
)
p = poll()
p.register(sock1, POLLIN)
p.register(sock2, POLLIN | POLLOUT)
p.unregister(sock1)
for fd, events in p.poll(3):
print(f"<socket.socket fd={fd}> is ready with {events}")
Like select.poll, winpoll.wsapoll objects acquire no special resources, thus
have no cleanup requirement (besides plain garbage collection).
Alternative to selectors.PollSelector/selectors.DefaultSelector
import sys
from selectors import (
EVENT_READ, EVENT_WRITE,
DefaultSelector, SelectSelector
)
if (DefaultSelector is SelectSelector) and (sys.platform == 'win32') and (sys.getwindowsversion() >= (10, 0, 19041)):
# https://github.com/python/cpython/issues/60711
from winpoll import WSAPollSelector as DefaultSelector
s = DefaultSelector()
s.register(sock1, EVENT_READ)
s.register(sock2, EVENT_READ | EVENT_WRITE)
s.unregister(sock1)
for (sock, _fd, _eventmask, _data), events in s.select(3):
print(f"{sock} is ready with {events}")
Limitations / Bugs
-
Does not work before Windows Vista.
- Last affected OS: Windows XP (EOL April 8, 2014; not supported by Python 3.7+ anyway.)
-
Outbound TCP connections don't correctly report failure-to-connect (
(POLLHUP | POLLERR | POLLWRNORM)) before Windows 10 version 2004 ("May 2020 Update" / "20H1" / "OS Build 19041").- Last affected OS: Windows 10 version 1909 (EOL May 10, 2022.)
Installation
Command-line
pip install "winpoll ; sys_platform == 'win32'"
requirements.txt
...
winpoll ; sys_platform == 'win32'
setup.py
...
setup(
...,
install_requires: [
...,
"winpoll ; sys_platform == 'win32'"
]
)
pyproject.toml
[project]
...
dependencies = [
...,
"winpoll ; sys_platform == 'win32'",
]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file winpoll-0.20301.2.tar.gz.
File metadata
- Download URL: winpoll-0.20301.2.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8531241770fdb92abb596a3d38bdab99cb3dc40b4968afb6dae944c8f3e2dade
|
|
| MD5 |
4cbc8aac46f028fb2080b9582306dd0a
|
|
| BLAKE2b-256 |
d094278de6af2a11d58c7ce8a5f7a5df9aa7e3242f524a239ff5a94efe31ea87
|
File details
Details for the file winpoll-0.20301.2-py3-none-any.whl.
File metadata
- Download URL: winpoll-0.20301.2-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c43cb1f804b72cd5208f5e7fa50ca8b604d1190bac7c061b31c42a3a49609e56
|
|
| MD5 |
8b16b1fbe5fd49e5f7fc3d51f1703d0c
|
|
| BLAKE2b-256 |
0330d0b22d31e73e0cfca1552f0f58690436f2e4e7b54c172aad82597bb7e426
|