Twisted IOCP Support

25.10.1 · active · verified Fri Apr 17

twisted-iocpsupport provides a C extension for Twisted's I/O Completion Ports (IOCP) reactor, primarily used on Windows for high-performance asynchronous I/O. It enhances the `twisted.internet.iocpreactor` module, making the IOCP reactor available for use. The current version is 25.10.1, with releases typically tied to Twisted's release cycle and Python version support, focusing on platform compatibility and binary wheels.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install and run a basic Twisted echo server using the IOCP reactor on Windows, which utilizes the `twisted-iocpsupport` extension for high-performance I/O. This example will only run the server if executed on a Windows operating system.

import os
from twisted.internet import protocol, reactor

# This library provides the underlying C extension for the IOCP reactor.
# The IOCP reactor is Windows-specific and offers performance benefits there.
if os.name == 'nt':
    from twisted.internet import iocpreactor
    iocpreactor.install()

    class Echo(protocol.Protocol):
        def dataReceived(self, data):
            self.transport.write(data)

    class EchoFactory(protocol.Factory):
        def buildProtocol(self, addr):
            return Echo()

    print("Starting IOCP reactor echo server on port 8000 (Windows only)...")
    reactor.listenTCP(8000, EchoFactory())
    reactor.run()
else:
    print("IOCP reactor is Windows-specific. Skipping quickstart on non-Windows OS.")
    print("Install and run on Windows to test this library's functionality.")

view raw JSON →