Skip to main content

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
  • No dependencies (besides Windows Vista or newer)
  • Python 3.6+ compatible

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.

  • Outbound TCP connections don't correctly report failure-to-connect ((POLLHUP | POLLERR | POLLWRNORM)) before Windows 10 Version 2004 (OS build 19041).

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

winpoll-0.20301.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

winpoll-0.20301.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file winpoll-0.20301.0.tar.gz.

File metadata

  • Download URL: winpoll-0.20301.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for winpoll-0.20301.0.tar.gz
Algorithm Hash digest
SHA256 688c824aa78a4f4ebaf1c825e1cfe80f265212b36d191bb8e8fe027208e3e1f7
MD5 737794af8325f3d1b366f051fb8e980d
BLAKE2b-256 95bd085894f5b81719157f0014e48cc19ef13764d98b4ceed3676eac8e0967f1

See more details on using hashes here.

File details

Details for the file winpoll-0.20301.0-py3-none-any.whl.

File metadata

  • Download URL: winpoll-0.20301.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for winpoll-0.20301.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28dd274d2a3338184e064e3ffcdb17afd50e6aaafd6336ed61571558dfc94468
MD5 fda5208e162ca3d2e7689f6e07a9ee33
BLAKE2b-256 c51003b7fba4087c5afe78919d840a05def102abd9fc66fe50cff5a8e6f72c9e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page