Skip to content

Implement Windows Support - #794

Open
Vizonex wants to merge 24 commits into
MagicStack:masterfrom
Vizonex:win
Open

Vizonex wants to merge 24 commits into
MagicStack:masterfrom
Vizonex:win

Conversation

@Vizonex

@Vizonex Vizonex commented Nov 22, 2026

Copy link
Copy Markdown

This is a redo of my older Pull Request from earlier this year. I want to still thank everybody for staying hyped and keeping me involved.

Let us finish what @1st1 started 10 years ago. My plans after this is merged is to start bringing as many optimizations from winloop to this library as I can, after that winloop will begin starting it's deprecation process until eventually it just installs uvloop as a dependency and then the winloop repo will be archived.

closes #14
closes #536
closes #652
closes #62

@Vizonex

Vizonex commented Nov 22, 2026

Copy link
Copy Markdown
Author

Lets ensure the other stuff works before I make tests for windows.

@Vizonex

Vizonex commented Nov 22, 2026

Copy link
Copy Markdown
Author

3.9 ubuntu is broken but we are ignoring that it's a workflow issue not a uvloop issue.

@Vizonex

Vizonex commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

If anyboy wants to fix any of the bugs I found feel free, It's been a nightmare to try and solve the bugs with processes in general, I have not found a reliable solution to the bugs in test_process.py, in windows, python parser fails to parse a handful of those multiline arguments, for example this code fails for some random reason telling me about an EOF at line 10 in the code:

import signal
import sys

def handler(signum, frame):
    if signum == signal.SIGUSR1:
        print('WORLD')

if sys.platform != 'win32':
    signal.signal(signal.SIGUSR1, handler)
a = input()
print(a)
a = input()
print(a)
exit(11)

The craizer part is that winloop does it fine. I can't seem to find the code difference either. But if anybody wants to whip out their AIs or other tools, editors coding IDES, etc, feel free to hop on in, You'll have to fork my branch under the win branch and send a pull request to it. For now I must rest. It's late for me. Tomorrow I will resume this.

This is fixed now

@Vizonex

Vizonex commented Nov 24, 2026

Copy link
Copy Markdown
Author

Vizonex/Winloop#194 Posting this here since it relates, it's a problem that has been preventing me from moving forward.

@Vizonex

Vizonex commented Nov 25, 2026

Copy link
Copy Markdown
Author

Problem solved for subprocesses an PR is incoming from my end.

…16)

* fix subprocess problems and enable more tests to start running again

* fix linting

* mark linux tests as non-reproducible

* reformat tests
@Vizonex

Vizonex commented Nov 26, 2026

Copy link
Copy Markdown
Author

1 test needs solving (unrelated) but this PR appears to be ready for merge.

@fantix I'll let this merge be your call but windows support is considered done. My work here is done and I'm proud of what me and my team has accomplished.

@Vizonex

Vizonex commented Nov 26, 2026

Copy link
Copy Markdown
Author

I'm planning to turn off the win fork for workflows when the PR is approved by a reviewer since I was having to do a lot of on/off with workflows to ensure everything worked correctly.

* Apply final changes before merging windows support with uvloop

* disable linux on test_process_delayed_stdio__not_paused__no_stdin

* remove win branch from tests.yml as local testing is complete
@Vizonex

Vizonex commented Nov 27, 2026

Copy link
Copy Markdown
Author

It's ready now.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical Windows defects remain, including a Win64 stack overwrite, incorrect signal registration, and source-distribution builds that fail without Unix tooling.

13 open issues
What changed in this PR

This PR extends uvloop’s libuv-backed asyncio implementation with native Windows build and runtime paths, addressing the long-standing Windows support requests.

Changes:

  • Adds Windows compilation of bundled libuv and removes the installation restriction.
  • Introduces Windows-specific subprocess, stream, polling, signal, DNS, and error handling.
  • Adds Windows CI jobs and adapts platform-dependent tests.
File Description
uvloop/​server.pyx Uses the cached asyncio cancellation exception.
uvloop/​loop.pyx Adds Windows subprocess, socket, and signal paths.
uvloop/​loop.pyi Modernizes type annotation syntax.
uvloop/​includes/​uv.pxd Adds libuv pipe and Windows process declarations.
uvloop/​includes/​system.pxd Adds Windows compatibility declarations and counter helpers.
uvloop/​includes/​stdlib.pxi Caches Windows-related constants and standard-library helpers.
uvloop/​includes/​python.pxd Adds a comment-only frame-helper TODO.
uvloop/​includes/​fork_handler.h Guards pthread use and adds a Windows stub.
uvloop/​includes/​compat.h Adds Windows wrappers, platform flags, and stdio checks.
uvloop/​handles/​stream.pyx Adapts stream writes and pipe reads for Windows.
uvloop/​handles/​process.pyx Adds Windows startup information and pipe-based subprocess stdio.
uvloop/​handles/​process.pxd Updates subprocess signatures for startup information.
uvloop/​handles/​poll.pyx Switches to socket-aware polling initialization.
uvloop/​handles/​fsevent.pyx Removes an extra blank line.
uvloop/​errors.pyx Adds Windows error-code and DNS-message handling.
uvloop/​dns.pyx Adds Windows address-conversion and hostname handling.
uvloop/​_testbase.py Adds Windows detection and platform-aware test setup.
tests/​test_unix.py Skips Unix socket tests on Windows and reformats code.
tests/​test_udp.py Adds Windows skips and loop-policy selection.
tests/​test_testbase.py Reformats existing test-helper assertions.
tests/​test_sourcecode.py Simplifies subprocess output capture and formatting.
tests/​test_sockets.py Adds Windows-specific skips and loop-policy selection.
tests/​test_signals.py Adapts signal expectations and skips for Windows.
tests/​test_runner.py Reformats existing runner tests.
tests/​test_regr1.py Reformats multiprocessing regression tests.
tests/​test_process_spawning.py Selects Windows C-runtime process functions.
tests/​test_pipes.py Skips unsupported Windows pipe and terminal cases.
tests/​test_libuv_api.py Reorders imports only.
tests/​test_fs_event.py Adds a Windows file-change test skip.
tests/​test_executors.py Simplifies iteration and reformats existing tests.
tests/​test_dns.py Adds Windows skips for address-result comparisons.
tests/​test_dealloc.py Reformats subprocess calls and assertions.
tests/​test_cython.py Simplifies coroutine-name assertions and reorders imports.
tests/​test_context.py Adapts transport context tests for Windows.
tests/​test_base.py Guards fcntl use and adjusts timer-test skips.
tests/​test_aiohttp.py Adds Windows loop-policy selection and simplifies client code.
tests/​__main__.py Enables multiprocessing freeze support on Windows.
setup.py Adds Windows compiler settings, libraries, and libuv sources.
pyproject.toml Comments out license classifiers.
.github/​workflows/​tests.yml Adds Windows jobs and adjusts matrix/debug-build coverage.

Review effort: Max

Comment thread setup.py
Comment on lines +170 to +173
if sys.platform != 'win32':
# Make sure configure and friends are present in case
# we are building from a git checkout.
_libuv_autogen(env)
Comment thread uvloop/handles/stream.pyx
# be an option, but the corresponding files have been created
# FILE_FLAG_OVERLAPPED set, but we don't want to go that way here.
# We detect pipes on Windows as pseudosockets.
if self._get_socket().family == uv.AF_UNIX:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a valid one?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fantix I'm working on a fix for it. Bit sizes have always been a problem. I have opened another PR on my end for applying many of these fixes. Vizonex#18

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fantix I finished resolving it. Cython code should now return uv_os_fd_t as inteneded without any size reductions.

static uv_os_fd_t __pyx_f_6uvloop_4loop_14UVSocketHandle__fileno(struct __pyx_obj_6uvloop_4loop_UVSocketHandle *__pyx_v_self) {
  uv_os_fd_t __pyx_v_fd;
  int __pyx_v_err;
  uv_os_fd_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_fileno", 0);

  /* "uvloop/handles/handle.pyx":232
 *             int err
 * 
 *         self._ensure_alive()             # <<<<<<<<<<<<<<
 *         err = uv.uv_fileno(self._handle, &fd)
 *         if err < 0:
*/
  __pyx_t_1 = ((struct __pyx_vtabstruct_6uvloop_4loop_UVSocketHandle *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._ensure_alive(((struct __pyx_obj_6uvloop_4loop_UVHandle *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "uvloop/handles/handle.pyx":233
 * 
 *         self._ensure_alive()
 *         err = uv.uv_fileno(self._handle, &fd)             # <<<<<<<<<<<<<<
 *         if err < 0:
 *             raise convert_error(err)
*/
  __pyx_v_err = uv_fileno(__pyx_v_self->__pyx_base._handle, (&__pyx_v_fd));

  /* "uvloop/handles/handle.pyx":234
 *         self._ensure_alive()
 *         err = uv.uv_fileno(self._handle, &fd)
 *         if err < 0:             # <<<<<<<<<<<<<<
 *             raise convert_error(err)
 * 
*/
  __pyx_t_2 = (__pyx_v_err < 0);

  if (unlikely(__pyx_t_2)) {


    /* "uvloop/handles/handle.pyx":235
 *         err = uv.uv_fileno(self._handle, &fd)
 *         if err < 0:
 *             raise convert_error(err)             # <<<<<<<<<<<<<<
 * 
 *         return fd
*/
    __pyx_t_1 = __pyx_f_6uvloop_4loop_convert_error(__pyx_v_err); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(1, 235, __pyx_L1_error)

    /* "uvloop/handles/handle.pyx":234
 *         self._ensure_alive()
 *         err = uv.uv_fileno(self._handle, &fd)
 *         if err < 0:             # <<<<<<<<<<<<<<
 *             raise convert_error(err)
 * 
*/
  }

  /* "uvloop/handles/handle.pyx":237
 *             raise convert_error(err)
 * 
 *         return fd             # <<<<<<<<<<<<<<
 * 
 *     cdef _new_socket(self):
*/
  {

    __pyx_r = __pyx_v_fd;
  }
  goto __pyx_L0;

  /* "uvloop/handles/handle.pyx":227
 *         self.__cached_socket = None
 * 
 *     cdef uv.uv_os_fd_t _fileno(self):             # <<<<<<<<<<<<<<
 *         cdef:
 *             uv.uv_os_fd_t fd
*/

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("uvloop.loop.UVSocketHandle._fileno", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;



  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
Comment thread uvloop/loop.pyx Resolved
Comment thread tests/test_base.py
self.assertGreater(finished - started, 0.04)

@unittest.skipIf(
sys.version_info[:2] <= (3, 12),
Comment thread tests/test_context.py Resolved
Comment thread uvloop/handles/process.pyx Resolved
Comment thread uvloop/handles/process.pyx Resolved
Comment thread uvloop/handles/stream.pyx Resolved
Comment thread uvloop/includes/system.pxd Resolved
Comment thread uvloop/loop.pyx
# Originally it was removed but brought back.
# SEE: https://github.com/Vizonex/Winloop/issues/153

args.extend(split_windows_shell_command(cmd))
Vizonex and others added 5 commits November 30, 2026 13:25
… on Windows'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* fix more code based on copilot's suggestions

* isolate _libuv_autogen away from windows

* resize variables in the compat write function and in uv_fileno

* add _conn_lost counter instead of rasing a runtime error

* ensure posix is set to false

* escape backslashes before splitting shell code into tokens

* throw error if uv_pipe fails while using __socketpair()
@Vizonex
Vizonex requested a review from fantix November 30, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants