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 sock, events in p.poll(timeout=3):
    print(f"Socket {sock} 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 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

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'

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.20295.1.tar.gz (10.1 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for winpoll-0.20295.1.tar.gz
Algorithm Hash digest
SHA256 d248840bae3ab5a6d90ede18fdc7176c896b4cf1e64e0de5d66a90d88f6918fe
MD5 5e95e4a6e3a5fbddab979c017507136f
BLAKE2b-256 de39f67bb9d4c65d3fb0512d124b7b8b143f61c9278a938643d48c673bd8b841

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