{"id":10315,"library":"twisted-iocpsupport","title":"Twisted IOCP Support","description":"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.","status":"active","version":"25.10.1","language":"en","source_language":"en","source_url":"https://github.com/twisted/twisted-iocpsupport","tags":["twisted","windows","async","io-completion-ports","reactor","performance"],"install":[{"cmd":"pip install twisted-iocpsupport","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"This library is a C extension for Twisted's I/O Completion Ports (IOCP) reactor and requires Twisted to function.","package":"twisted"}],"imports":[{"note":"This library provides the underlying C extension for `twisted.internet.iocpreactor`. User code typically imports the `iocpreactor` module and then calls `iocpreactor.install()` to activate the IOCP reactor.","symbol":"iocpreactor","correct":"from twisted.internet import iocpreactor"}],"quickstart":{"code":"import os\nfrom twisted.internet import protocol, reactor\n\n# This library provides the underlying C extension for the IOCP reactor.\n# The IOCP reactor is Windows-specific and offers performance benefits there.\nif os.name == 'nt':\n    from twisted.internet import iocpreactor\n    iocpreactor.install()\n\n    class Echo(protocol.Protocol):\n        def dataReceived(self, data):\n            self.transport.write(data)\n\n    class EchoFactory(protocol.Factory):\n        def buildProtocol(self, addr):\n            return Echo()\n\n    print(\"Starting IOCP reactor echo server on port 8000 (Windows only)...\")\n    reactor.listenTCP(8000, EchoFactory())\n    reactor.run()\nelse:\n    print(\"IOCP reactor is Windows-specific. Skipping quickstart on non-Windows OS.\")\n    print(\"Install and run on Windows to test this library's functionality.\")","lang":"python","description":"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."},"warnings":[{"fix":"Only install and use `twisted-iocpsupport` on Windows platforms for its intended purpose. On other operating systems, Twisted will default to other reactors (e.g., epoll, kqueue, select).","message":"This library is platform-specific and primarily designed for Windows. While it might install on other systems, its functionality (the IOCP reactor) is only available and beneficial on Windows.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that `from twisted.internet import iocpreactor; iocpreactor.install()` is called at the very beginning of your application's lifecycle, before any calls to `reactor.run()` or `reactor.listenTCP()`.","message":"To activate the IOCP reactor provided by this extension, `iocpreactor.install()` must be explicitly called before other reactor-related operations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"On Windows, ensure you have the appropriate Microsoft C++ Build Tools installed (e.g., Visual C++ 14.0 or greater). Check the `pip install` logs for specific compiler errors. Using a Python version for which pre-built wheels exist is often the easiest solution.","message":"Installation can fail if pre-built wheels are not available for your specific Python version and architecture, requiring compilation from source.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure you are on a Windows operating system. Check the `pip install twisted-iocpsupport` logs for any build errors. If not on Windows, remove `iocpreactor.install()` or ensure its call is conditional on `os.name == 'nt'`.","cause":"The `twisted-iocpsupport` C extension failed to install correctly, or you are attempting to use the IOCP reactor on a non-Windows platform.","error":"ImportError: cannot import name '_iocpsupport' from 'twisted.internet.iocpreactor'"},{"fix":"Call `iocpreactor.install()` only once, ideally as the first Twisted-related operation in your application, before any `reactor` imports that might implicitly install a default reactor.","cause":"The `iocpreactor.install()` function (or any `reactor.install()` variant) was called more than once in the application's lifecycle.","error":"RuntimeError: The reactor is already installed."},{"fix":"Install the 'Desktop development with C++' workload from Visual Studio Installer, or specifically the Microsoft C++ Build Tools, as indicated in the error message. Alternatively, try to use a Python version for which a pre-built wheel is available on PyPI.","cause":"During `pip install`, `twisted-iocpsupport` attempted to build from source on Windows, but the necessary C++ compiler tools were not found.","error":"error: Microsoft Visual C++ 14.0 or greater is required. Get it with \"Microsoft C++ Build Tools\": https://visualstudio.microsoft.com/visual-cpp-build-tools/"}]}