Skip to content

Enhance Cygwin support #149879

Closed
8 of 11 issues completed
Closed

Description

@vstinner

Cygwin is a free and open-source Unix-like environment and command-line interface for Microsoft Windows. There is an on-going effort to support Cygwin in Python. I create this meta-issue to track other Cygwin sub-issues.

To install Cygwin on Windows and build CPython in Cygwin, you can use these commands:

  • Download https://cygwin.com/setup-x86_64.exe
  • Run setup-x86_64.exe : select gcc-core, make, libffi-devel, libssl-devel and zlib-devel packages (I also installed vim, my favorite text editor 😁).
  • Start Cygwin shell (icon on the desktop).
  • Type: git config --global core.autocrlf input -- I had issues with newlines in the ./configure script without that.
  • Run git clone https://github.com/python/cpython/ --depth=1
  • Type: cd cpython
  • Type: ./configure --with-pydebug --cache-file=../configure.cache --without-mimalloc
  • Type: make -j8

mimalloc is disabled because it fails at startup on Cygwin with:

$ PYTHONMALLOC=mimalloc ./python.exe -c pass
mimalloc: warning: cannot decommit OS memory (error: 22 (0x16), address: 0x20000430000, size: 0x1bd0000 bytes)
mimalloc: assertion failed: at "Objects/mimalloc/os.c":444, mi_os_decommit_ex
  assertion: "err == 0"
Aborted

Linked PRs

Activity

  1. vstinner commented on May 15, 2026

    @vstinner
    MemberAuthor

    I suggest you set up a buildbot, or add it to the CI. Otherwise I fear your work will be broken by future commits :-(

    Right now, around 60 tests are failing. It's too early to consider adding a buildbot.

  2. added 2 commits that reference this issue on May 15, 2026
  3. zware commented on May 15, 2026

    @zware
    Member

    Right now, around 60 tests are failing. It's too early to consider adding a buildbot.

    As long as the tests can finish cleanly even if failing, I think an 'unstable' worker could be added any time.

  4. added 4 commits that reference this issue on May 15, 2026
  5. vstinner commented on May 15, 2026

    @vstinner
    MemberAuthor

    With the latest batch of fixes: 47 tests failed on 505.

    test.test_multiprocessing_forkserver.test_misc
    test.test_multiprocessing_forkserver.test_manager
    test.test_multiprocessing_fork.test_misc
    test.test_concurrent_futures.test_process_pool
    test.test_multiprocessing_forkserver.test_preload
    test_multiprocessing_main_handling
    test.test_concurrent_futures.test_deadlock
    test.test_concurrent_futures.test_wait
    test_logging
    test.test_concurrent_futures.test_as_completed
    test.test_multiprocessing_forkserver.test_threads
    test.test_concurrent_futures.test_init
    test.test_concurrent_futures.test_shutdown
    test.test_multiprocessing_spawn.test_misc
    test_multiprocessing_spawn.test_processes
    test_re
        forkserver/recvfds() errors
    
    test_venv
        venv python.exe fails to locate the cygpython DLL
    test_sysconfig
        ERROR: test_makefile_overwrites_config_vars()
        venv python.exe fails to locate the cygpython DLL
    
    test_zipfile
        test_extract_dir_backslash() fails
    
    test_signal
        test_stress_delivery_dependent
        OSError: Signal 14 ignored due to race condition
    
        test_stress_delivery_simultaneous
        OSError: Signal 14 ignored due to race condition
    
    test_strptime
        ERROR: test_date_locale (test.test_strptime.StrptimeTests.test_date_locale) (locale='my_MM')
        ERROR: test_date_locale (test.test_strptime.StrptimeTests.test_date_locale) (locale='or_IN')
        ERROR: test_date_locale2 (test.test_strptime.StrptimeTests.test_date_locale2) (locale='my_MM')
        ERROR: test_date_time_locale (test.test_strptime.StrptimeTests.test_date_time_locale) (locale='my_MM')
        ERROR: test_date_time_locale (test.test_strptime.StrptimeTests.test_date_time_locale) (locale='or_IN')
        ERROR: test_date_time_locale2 (test.test_strptime.StrptimeTests.test_date_time_locale2) (locale='my_MM')
        ERROR: test_time_locale (test.test_strptime.StrptimeTests.test_time_locale) (locale='or_IN')
    
    test_ssl
        88 errors, 1 failure
    
    test_statistics
        FAIL: test_sqrtprod_helper_function_improved_accuracy (test.test_statistics.TestCorrelationAndCovariance.test_sqrtprod_helper_function_improved_accuracy)
    
    test_socket
        2 errors, 30 failures
    
    test_tempfile
        FAIL: test_textmode (test.test_tempfile.TestMkstempInner.test_textmode)
    
    test_ftplib
        ERROR: test_abort (test.test_ftplib.TestFTPClass.test_abort)
    
    test.test_os.test_posix
        2 failures
    test.test_os.test_os
        2 errors, 2 failures
    
    test_ioctl
        ERROR: test_ioctl_clear_input_or_output (test.test_ioctl.IoctlTestsPty.test_ioctl_clear_input_or_output)
    test_termios
        ERROR: test_tcflow (test.test_termios.TestFunctions.test_tcflow)
        ERROR: test_tcsendbreak (test.test_termios.TestFunctions.test_tcsendbreak)
        FAIL: test_tcflow_errors (test.test_termios.TestFunctions.test_tcflow_errors)
        FAIL: test_tcflush_clear_input_or_output (test.test_termios.TestFunctions.test_tcflush_clear_input_or_output)
        FAIL: test_tcsetattr_errors (test.test_termios.TestFunctions.test_tcsetattr_errors)
    
    test_embed
        FAIL: test_init_pybuilddir (test.test_embed.InitConfigTests.test_init_pybuilddir)
        FAIL: test_init_pyvenv_cfg (test.test_embed.InitConfigTests.test_init_pyvenv_cfg)
        FAIL: test_init_setpath (test.test_embed.InitConfigTests.test_init_setpath)
        FAIL: test_init_setpythonhome (test.test_embed.InitConfigTests.test_init_setpythonhome)
    
    test_shutil
        11 errors, 2 failures
    
    test_c_stack_unwind
        FAIL: test_manual_unwind_finds_expected_frames (test.test_c_stack_unwind.ManualStackUnwindTests.test_manual_unwind_finds_expected_frames) (env={'PYTHON_JIT': '0'})
    
    test__locale
        FAIL: test_alt_digits_nl_langinfo (test.test__locale._LocaleTests.test_alt_digits_nl_langinfo) (locale='ja_JP.UTF-8')
    
    test_c_locale_coercion
        FAIL: test_LC_ALL_set_to_C (test.test_c_locale_coercion.LocaleCoercionTests.test_LC_ALL_set_to_C) (default_locale=True, PYTHONCOERCECLOCALE='warn')
        FAIL: test_PYTHONCOERCECLOCALE_set_to_zero (test.test_c_locale_coercion.LocaleCoercionTests.test_PYTHONCOERCECLOCALE_set_to_zero) (default_locale=True, PYTHONCOERCECLOCALE='0')
    
    test_capi
        mimalloc issues:
            FAIL: test_api_misuse (test.test_capi.test_mem.PyMemMimallocDebugTests.test_api_misuse)
            FAIL: test_buffer_overflow (test.test_capi.test_mem.PyMemMimallocDebugTests.test_buffer_overflow)
            FAIL: test_pymem_malloc_without_gil (test.test_capi.test_mem.PyMemMimallocDebugTests.test_pymem_malloc_without_gil)
            FAIL: test_pyobject_forbidden_bytes_is_freed (test.test_capi.test_mem.PyMemMimallocDebugTests.test_pyobject_forbidden_bytes_is_freed)
            FAIL: test_pyobject_freed_is_freed (test.test_capi.test_mem.PyMemMimallocDebugTests.test_pyobject_freed_is_freed)
            FAIL: test_pyobject_malloc_without_gil (test.test_capi.test_mem.PyMemMimallocDebugTests.test_pyobject_malloc_without_gil)
            FAIL: test_pyobject_null_is_freed (test.test_capi.test_mem.PyMemMimallocDebugTests.test_pyobject_null_is_freed)
            FAIL: test_pyobject_uninitialized_is_freed (test.test_capi.test_mem.PyMemMimallocDebugTests.test_pyobject_uninitialized_is_freed)
        misc issues:
            FAIL: test_allow_specialization_call (test.test_capi.test_misc.Test_Pep523AllowSpecialization.test_allow_specialization_call)
            FAIL: test_is_specialization_enabled_after_restore (test.test_capi.test_misc.Test_Pep523AllowSpecialization.test_is_specialization_enabled_after_restore)
            FAIL: test_is_specialization_enabled_default (test.test_capi.test_misc.Test_Pep523AllowSpecialization.test_is_specialization_enabled_default)
            FAIL: test_is_unique_temporary (test.test_capi.test_object.CAPITest.test_is_unique_temporary)
    
    test_math
        5 errors, 33 failures
    
    test_cmd_line
        FAIL: test_pythonmalloc (test.test_cmd_line.CmdLineTest.test_pythonmalloc) (env_var='mimalloc', name='mimalloc')
        FAIL: test_pythonmalloc (test.test_cmd_line.CmdLineTest.test_pythonmalloc) (env_var='mimalloc_debug', name='mimalloc_debug')
        mimalloc: warning: cannot decommit OS memory (error: 22 (0x16), address: 0x20000470000, size: 0x1b90000 bytes)
        mimalloc: assertion failed: at "Objects/mimalloc/os.c":444, mi_os_decommit_ex
          assertion: "err == 0"
    
    test_resource
        ERROR: test_fsize_enforced (test.test_resource.ResourceTest.test_fsize_enforced)
        ERROR: test_fsize_not_too_big (test.test_resource.ResourceTest.test_fsize_not_too_big)
        ERROR: test_setrusage_refcount (test.test_resource.ResourceTest.test_setrusage_refcount)
    
    test_compileall
        ERROR: test_ddir_empty_multiple_workers (test.test_compileall.CompileallTestsWithSourceEpoch.test_ddir_empty_multiple_workers)
        ERROR: test_ddir_multiple_workers (test.test_compileall.CompileallTestsWithSourceEpoch.test_ddir_multiple_workers)
        ERROR: test_ddir_empty_multiple_workers (test.test_compileall.CompileallTestsWithoutSourceEpoch.test_ddir_empty_multiple_workers)
        ERROR: test_ddir_multiple_workers (test.test_compileall.CompileallTestsWithoutSourceEpoch.test_ddir_multiple_workers)
        FAIL: test_workers (test.test_compileall.CommandLineTestsNoSourceEpoch.test_workers)
        FAIL: test_workers (test.test_compileall.CommandLineTestsWithSourceEpoch.test_workers)
    
  6. added a commit that references this issue on May 15, 2026
  7. vstinner commented on May 15, 2026

    @vstinner
    MemberAuthor
  8. added 4 commits that reference this issue on May 15, 2026
  9. carlo-bramini commented on May 17, 2026

    @carlo-bramini
    Contributor

    In the first post, what about adding also libexpat-devel package and adding --with-system-expat option to configure script?

  10. StanFromIreland commented on May 17, 2026

    @StanFromIreland
    Member

    We already bundle latest expat? In general those options are for distributors, not for development.

  11. embray commented on May 18, 2026

    @embray
    Contributor

    @vstinner Nice to see you working on this. I was trying quite a number of years ago to get various Cygwin patches to cpython upstream, and was maintaining a Cygwin builtbot for a while. As is typical the job that was funding that work ran out and I gradually drifted away from it before the effort was complete.

    Nevertheless, happy to provide any assistance to this if the need arises.

    https://github.com/embray/PyCygwin might also be of use; not sure. It's written using Cython so probably not directly, but has some useful tools for handling path conversions (esp for #90907)

  12. vstinner commented on May 18, 2026

    @vstinner
    MemberAuthor

    Recent Cygwin changes:

    • libpython DLL was renamed to cygpython DLL (ex: cygpython3.16d.dll)
    • importlib._bootstrap_external.EXTENSION_SUFFIXES: '.cpython-316d.dll' was added to ['.cpython-316d.dll', '.dll']
    • sys.orig_argv[0] was modified to include .exe suffix. For example, /python.exe -c 'import sys; print(repr(sys.orig_argv[0]))' displays './python.exe'.
    • Set _PYTHREAD_NAME_MAXLEN macro to 16 (bytes): needed to fix _thread.set_name().
    • test_os.test_os: timerfd_gettime_ns() behaves differently on Cygwin, I had to adapt the test. It's maybe a bug in Cygwin?
    • socket: I disabled SCM_RIGHTS, sendmsg(), recvmsg(), and sethostname() (it doesn't report failures) features. It seems like ancdata are not supported in Cygwin.

    Cygwin status:

    • msvcrt extension is not built: Cygwin doesn't provide <conio.h> nor <sys/locking.h> header files.
    • _winapi extension is not built.
  13. added a commit that references this issue on May 18, 2026
  14. vstinner commented on May 18, 2026

    @vstinner
    MemberAuthor

    I think that we have to put some limits in Cygwin support: we cannot support the full Windows API (in C code).

    So it's a good thing that MS_WINDOWS macro is false in C code, and that sys.platform == 'win32' is false in Python. Cygwin uses the "other" code path (Unix-like).


    Supporting forkserver start method in multiprocessing requires the _winapi extension and _multiprocessing.closesocket function.

    Supporting _multiprocessing.closesocket function in Cygwin seems to be complicated: #include <winsock2.h> introduces a conflict on the select() function already defined differently by <sys/select.h>. The <sys/select.h> header is included by <sys/types.h> which is included by <Python.h>.

    For multiprocessing, IMO it's acceptable to only support "start" and "fork" start methods.


    Using the Windows code path in subprocess requires msvcrt and _winapi. But building msvcrt extension fails on Cygwin because of missing <conio.h> nor <sys/locking.h> header files. So subprocess is implemented with fork+exec using _posixsubprocess extension. It just works on Cygwin!

  15. carlo-bramini commented on May 19, 2026

    @carlo-bramini
    Contributor

    I think that we have to put some limits in Cygwin support: we cannot support the full Windows API (in C code).

    If I can say my opinion, some fixed positions must be taken about the support for Cygwin.

    When running an application on Cygwin, the operating system is not Windows.
    The operating system IS Cygwin.
    It is also true that Cygwin can use Windows APIs.
    It supports some customized headers that can be included and used together with POSIX functions, but they must be used with some care.
    For example, Cygwin can get advantages by using built-in audio frameworks like Winmm/DirectSound/Wasapi, instead of using thirdy party libraries.
    However, as general rule, an user should forget that the heart behind Cygwin is Windows.
    Instead, he must think like using a true UNIX platform.

  16. embray commented on May 19, 2026

    @embray
    Contributor

    Supporting forkserver start method in multiprocessing requires the _winapi extension and _multiprocessing.closesocket function.

    I agree. I remember trying to fix that some years ago and throwing my hands up. It's not that it's impossible, strictly speaking. I got some patches into Cygwin back then to better support some socket edge cases though I don't recall the details. But someone would have to be very specifically motivated -- I think as a first pass it's OK to mark it as not supported.

  17. vstinner commented on May 19, 2026

    @vstinner
    MemberAuthor

    The Cygwin python39 package has many interesting patches: https://cygwin.com/cgit/cygwin-packages/python39/tree/

    (Patches on distutils and setup.py are outdated, since both have been removed.)

    There is an interesting 3.6.12-socketmodule.patch:

    diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
    index 442834a..932b0f2 100644
    --- a/Modules/socketmodule.c
    +++ b/Modules/socketmodule.c
    @@ -1139,6 +1136,14 @@ init_sockobject(socket_state *state, PySocketSockObject *s,
             }
         }
         s->state = state;
    +#ifdef __CYGWIN__
    +    /* Temporarily work around AF_UNIX credential passing issues */
    +    if (s->sock_family == AF_UNIX && s->sock_fd != -1) {
    +        if (setsockopt(s->sock_fd, SOL_SOCKET, SO_PEERCRED, 0, 0) == -1) {
    +            /* ignore error returns */;
    +        }
    +    }
    +#endif
         return 0;
     }
     

    Sadly, even if I apply this patch, sending file descriptors still fail: ancdata is always empty on Cygwin. I don't know if ancdata is supposed to be supported or not on Cygwin. I disabled sendmsg()/recvmsg() in the socket module on Cygwin.


    I wrote this test programs to test send_fds() / recv_fds().

    client.py:

    import socket
    
    fp = open(__file__)
    fd = fp.fileno()
    
    with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
        #client.setsockopt(socket.SOL_SOCKET, socket.SO_PEERCRED, 0)
        client.connect("/tmp/test")
    
        fds = [fd]
        print("fds", fds)
        socket.send_fds(client, [b'data'], fds)
        data = client.recv(1024)
        print(data)
    
        client.close()
    
    fp.close()

    server.py:

    import os
    import socket
    
    try:
        os.unlink("/tmp/test")
    except OSError:
        pass
    
    with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as server:
        #server.setsockopt(socket.SOL_SOCKET, socket.SO_PEERCRED, 0)
        server.bind("/tmp/test")
        server.listen(1)
        print("listen")
        client, addr = server.accept()
    
        with client:
            msg, fds, flags, addr = socket.recv_fds(client, 1024, 1)
            print("msg", msg)
            print(fds)
            fd = fds[0]
            data = os.read(fd, 1024)
            print(data)
            client.sendall(data)

    On Cygwin, the server gets an empty list of file descriptors (fds), and ancdata is empty in recv_fds().

  18. vstinner commented on May 19, 2026

    @vstinner
    MemberAuthor

    Rust has a Socket::set_no_peercred method for setsockopt(s->sock_fd, SOL_SOCKET, SO_PEERCRED, 0, 0):

    On Cygwin, a Unix domain socket connect blocks until the server accepts it. If the behavior is not expected, try [Socket::set_no_peercred] (Cygwin only).

  19. added 2 commits that reference this issue on May 19, 2026
  20. added 2 commits that reference this issue on May 22, 2026
  21. added 4 commits that reference this issue on May 22, 2026
  22. vstinner commented on May 25, 2026

    @vstinner
    MemberAuthor

    Update: 29 tests fail.

    test_ssl
        <88 errors>
    
    test_math
        <38 errors>
    
    test_shutil
        <13 errors>
    
    ValueError: cannot find context for 'forkserver'
        test_concurrent_futures.test_deadlock
            ERROR: test_crash_at_task_unpickle (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_crash_at_task_unpickle)
            ERROR: test_crash_big_data (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_crash_big_data)
            ERROR: test_crash_during_func_exec_on_worker (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_crash_during_func_exec_on_worker)
            ERROR: test_crash_during_result_pickle_on_worker (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_crash_during_result_pickle_on_worker)
            ERROR: test_error_at_task_pickle (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_error_at_task_pickle)
            ERROR: test_error_at_task_unpickle (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_error_at_task_unpickle)
            ERROR: test_error_during_func_exec_on_worker (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_error_during_func_exec_on_worker)
            ERROR: test_error_during_result_pickle_on_worker (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_error_during_result_pickle_on_worker)
            ERROR: test_error_during_result_unpickle_in_result_handler (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_error_during_result_unpickle_in_result_handler)
            ERROR: test_exit_at_task_unpickle (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_exit_at_task_unpickle)
            ERROR: test_exit_during_func_exec_on_worker (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_exit_during_func_exec_on_worker)
            ERROR: test_exit_during_result_pickle_on_worker (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_exit_during_result_pickle_on_worker)
            ERROR: test_exit_during_result_unpickle_in_result_handler (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_exit_during_result_unpickle_in_result_handler)
            ERROR: test_gh105829_should_not_deadlock_if_wakeup_pipe_full (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_gh105829_should_not_deadlock_if_wakeup_pipe_full)
            ERROR: test_shutdown_deadlock (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_shutdown_deadlock)
            ERROR: test_shutdown_deadlock_pickle (test.test_concurrent_futures.test_deadlock.ProcessPoolForkserverExecutorDeadlockTest.test_shutdown_deadlock_pickle)
        test_concurrent_futures.test_as_completed
            ERROR: test_correct_timeout_exception_msg (test.test_concurrent_futures.test_as_completed.ProcessPoolForkserverAsCompletedTest.test_correct_timeout_exception_msg)
            ERROR: test_duplicate_futures (test.test_concurrent_futures.test_as_completed.ProcessPoolForkserverAsCompletedTest.test_duplicate_futures)
            ERROR: test_free_reference_yielded_future (test.test_concurrent_futures.test_as_completed.ProcessPoolForkserverAsCompletedTest.test_free_reference_yielded_future)
            ERROR: test_future_times_out (test.test_concurrent_futures.test_as_completed.ProcessPoolForkserverAsCompletedTest.test_future_times_out)
            ERROR: test_no_timeout (test.test_concurrent_futures.test_as_completed.ProcessPoolForkserverAsCompletedTest.test_no_timeout)
        test_concurrent_futures.test_init
            ERROR: test_initializer (test.test_concurrent_futures.test_init.ProcessPoolForkserverFailingInitializerTest.test_initializer)
            ERROR: test_initializer (test.test_concurrent_futures.test_init.ProcessPoolForkserverInitializerTest.test_initializer)
            FAIL: test_forkserver (test.test_concurrent_futures.test_init.FailingInitializerResourcesTest.test_forkserver)
        test_concurrent_futures.test_shutdown
            ERROR: test_cancel_futures (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_cancel_futures)
            ERROR: test_context_manager_shutdown (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_context_manager_shutdown)
            ERROR: test_del_shutdown (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_del_shutdown)
            ERROR: test_hang_gh83386 (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_hang_gh83386)
            ERROR: test_hang_gh94440 (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_hang_gh94440)
            ERROR: test_hang_issue12364 (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_hang_issue12364)
            ERROR: test_interpreter_shutdown (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_interpreter_shutdown)
            ERROR: test_processes_terminate (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_processes_terminate)
            ERROR: test_run_after_shutdown (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_run_after_shutdown)
            ERROR: test_shutdown_gh_132969_case_1 (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_shutdown_gh_132969_case_1)
            ERROR: test_shutdown_gh_132969_case_2 (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_shutdown_gh_132969_case_2)
            ERROR: test_shutdown_no_wait (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_shutdown_no_wait)
            ERROR: test_submit_after_interpreter_shutdown (test.test_concurrent_futures.test_shutdown.ProcessPoolForkserverProcessPoolShutdownTest.test_submit_after_interpreter_shutdown)
        test.test_concurrent_futures.test_wait
            ERROR: test_20369 (test.test_concurrent_futures.test_wait.ProcessPoolForkserverWaitTest.test_20369)
            ERROR: test_all_completed (test.test_concurrent_futures.test_wait.ProcessPoolForkserverWaitTest.test_all_completed)
            ERROR: test_first_completed (test.test_concurrent_futures.test_wait.ProcessPoolForkserverWaitTest.test_first_completed)
            ERROR: test_first_completed_some_already_completed (test.test_concurrent_futures.test_wait.ProcessPoolForkserverWaitTest.test_first_completed_some_already_completed)
            ERROR: test_first_exception (test.test_concurrent_futures.test_wait.ProcessPoolForkserverWaitTest.test_first_exception)
            ERROR: test_first_exception_one_already_failed (test.test_concurrent_futures.test_wait.ProcessPoolForkserverWaitTest.test_first_exception_one_already_failed)
            ERROR: test_first_exception_some_already_complete (test.test_concurrent_futures.test_wait.ProcessPoolForkserverWaitTest.test_first_exception_some_already_complete)
            ERROR: test_timeout (test.test_concurrent_futures.test_wait.ProcessPoolForkserverWaitTest.test_timeout)
    
    test_venv
        venv python fails to located cygpython DLL
    
        ERROR: test_executable (test.test_venv.BasicTest.test_executable)
        ERROR: test_multiprocessing (test.test_venv.BasicTest.test_multiprocessing)
        ERROR: test_multiprocessing_recursion (test.test_venv.BasicTest.test_multiprocessing_recursion)
        ERROR: test_prefixes (test.test_venv.BasicTest.test_prefixes)
        ERROR: test_special_chars_bash (test.test_venv.BasicTest.test_special_chars_bash)
        ERROR: test_sysconfig (test.test_venv.BasicTest.test_sysconfig) [get_preferred_scheme("prefix")]
        ERROR: test_sysconfig (test.test_venv.BasicTest.test_sysconfig) [get_default_scheme()]
        ERROR: test_sysconfig (test.test_venv.BasicTest.test_sysconfig) [is_python_build()]
        ERROR: test_sysconfig (test.test_venv.BasicTest.test_sysconfig) [get_makefile_filename()]
        ERROR: test_sysconfig (test.test_venv.BasicTest.test_sysconfig) [get_config_h_filename()]
        ERROR: test_sysconfig (test.test_venv.BasicTest.test_sysconfig) [get_config_var("Py_GIL_DISABLED")]
        ERROR: test_sysconfig (test.test_venv.BasicTest.test_sysconfig) [executable]
        ERROR: test_sysconfig (test.test_venv.BasicTest.test_sysconfig) [base_prefix]
        ERROR: test_zippath_from_non_installed_posix (test.test_venv.BasicTest.test_zippath_from_non_installed_posix)
        ERROR: test_explicit_no_pip (test.test_venv.EnsurePipTest.test_explicit_no_pip)
        ERROR: test_no_pip_by_default (test.test_venv.EnsurePipTest.test_no_pip_by_default)
    
    test_strptime
        ERROR: test_date_locale (test.test_strptime.StrptimeTests.test_date_locale) (locale='my_MM')
        ERROR: test_date_locale (test.test_strptime.StrptimeTests.test_date_locale) (locale='or_IN')
        ERROR: test_date_locale2 (test.test_strptime.StrptimeTests.test_date_locale2) (locale='my_MM')
        ERROR: test_date_time_locale (test.test_strptime.StrptimeTests.test_date_time_locale) (locale='my_MM')
        ERROR: test_date_time_locale (test.test_strptime.StrptimeTests.test_date_time_locale) (locale='or_IN')
        ERROR: test_date_time_locale2 (test.test_strptime.StrptimeTests.test_date_time_locale2) (locale='my_MM')
        ERROR: test_time_locale (test.test_strptime.StrptimeTests.test_time_locale) (locale='or_IN')
    
    test_termios
        ERROR: test_tcdrain (test.test_termios.TestFunctions.test_tcdrain)
        ERROR: test_tcflow (test.test_termios.TestFunctions.test_tcflow)
        ERROR: test_tcsendbreak (test.test_termios.TestFunctions.test_tcsendbreak)
        FAIL: test_tcflow_errors (test.test_termios.TestFunctions.test_tcflow_errors)
        FAIL: test_tcflush_clear_input_or_output (test.test_termios.TestFunctions.test_tcflush_clear_input_or_output)
        FAIL: test_tcsetattr_errors (test.test_termios.TestFunctions.test_tcsetattr_errors)
    
    test_embed
        FAIL: test_init_pybuilddir (test.test_embed.InitConfigTests.test_init_pybuilddir)
        FAIL: test_init_pyvenv_cfg (test.test_embed.InitConfigTests.test_init_pyvenv_cfg)
        FAIL: test_init_setpath (test.test_embed.InitConfigTests.test_init_setpath)
        FAIL: test_init_setpythonhome (test.test_embed.InitConfigTests.test_init_setpythonhome)
    
    test_multiprocessing_fork.test_processes
        FAIL: test_wait_result (test.test_multiprocessing_fork.test_processes.WithProcessesTestCondition.test_wait_result)
    
    test_asyncio.test_ssl
        ERROR: test_remote_shutdown_receives_trailing_data_on_slow_socket (test.test_asyncio.test_ssl.TestSSL.test_remote_shutdown_receives_trailing_data_on_slow_socket)
    
    test_c_stack_unwind failed
        FAIL: test_manual_unwind_finds_expected_frames (test.test_c_stack_unwind.ManualStackUnwindTests.test_manual_unwind_finds_expected_frames) (env={'PYTHON_JIT': '0'})
    
    test_multiprocessing_spawn.test_processes
        test_wait_result()
    
    test_statistics
        test_sqrtprod_helper_function_improved_accuracy()
    
    test_capi
        test_allow_specialization_call()
    
    test_multiprocessing_spawn.test_misc
        test_resource_tracker_sigterm()
    test_multiprocessing_fork.test_misc
        test_resource_tracker_sigterm()
    
    test_sysconfig
        test_makefile_overwrites_config_vars()
    
    test_ftplib
        test_abort()
    
    test_zipfile
        test_extract_dir_backslash()
    
    test_asyncio.test_subprocess
        <altered the execution environment>
        <threading._dangling was modified>
    
    test_httpservers
        <test_get() hangs>
    test_asyncio.test_events
        <test_create_unix_server() hangs>
    test_asyncio.test_streams
        <test_start_unix_server() hangs>
    test_asyncio.test_sock_lowlevel
        <test_unix_sock_client_ops() hangs>
    test_concurrent_futures.test_process_pool
        <test_force_shutdown_workers_stops_pool() hangs>
    
  23. added 4 commits that reference this issue on May 25, 2026
  24. vstinner commented on May 25, 2026

    @vstinner
    MemberAuthor

    To fix test_asyncio on Cygwin, I disabled tests on UNIX sockets and I modified the subprocess implementation to use a socket for stdin: see commit be715d7.

  25. added 9 commits that reference this issue on May 25, 2026
  26. vstinner commented on May 26, 2026

    @vstinner
    MemberAuthor

    Update: 8 tests are failing.

    test_shutil
        (11 errors, 2 failures)
    
    test_c_stack_unwind
        test_manual_unwind_finds_expected_frames()
    
    test_multiprocessing_spawn.test_processes
        test_wait_result()
    test_multiprocessing_fork.test_processes
        test_wait_result()
    
    test_zipfile
        test_extract_dir_backslash()
    
    test_capi
        test_allow_specialization_call()
    
    test_concurrent_futures.test_process_pool
        <test_force_shutdown_workers() hangs>
        <test_force_shutdown_workers_stops_pool hangs>
    test_asyncio.test_ssl
        <test_remote_shutdown_receives_trailing_data_on_slow_socket hangs>
    

    The remaining failures are the most complex ones to fix. I'm not sure if it's worth it to fix the last issues.

    test_grp also fails, but I have a pending fix: PR gh-150495.

    There are also some race conditions.

    • test_signal fails sometimes with "env changed" with "OSError: Signal 14 ignored due to race condition".
    • test_os.test_os: test_timerfd_select() fails sometimes.

    The following test logs warnings:

    • test_asyncio.test_subprocess: test_close_dont_kill_finished() leaks a thread.

    And there is a Cygwin bug:

    • test_threading: test_is_alive_after_fork() fails sometimes with *** fatal error in forked process - failed to create new win32 semaphore, currentvalue 4294967295, Win32 error 87.
  27. vstinner commented on May 26, 2026

    @vstinner
    MemberAuthor

    Recent changes:

    • Fix venv: copy also the cygpython DLL.
    • test_strptime: skip locales when they are known to fail on Cygwin.
    • test_math: skip tests on math.fma(), math.hypot() and math.log2() which are known to fail on newlib C library (Cygwin).
    • Fix ssl: catch EAGAIN in the getpeername() failure code path.
    • Fix test_termios and test_ioctl: skip tests on ENOTTY error.
  28. vstinner commented on May 26, 2026

    @vstinner
    MemberAuthor

    I created Enhance Cygwin support topic on discusss.python.org to discuss what should be the next steps for the Cygwin support.

  29. added a commit that references this issue on May 26, 2026
  30. carlo-bramini commented on May 28, 2026

    @carlo-bramini
    Contributor

    About:

    * test_math: skip tests on math.fma(), math.hypot() and math.log2() which are known to fail on newlib C library (Cygwin).
    

    On Cygwin, some of the test on the mathematical functions fail.
    You can see this error on screen:

    0:23:31 load avg: 0.64 [18/40/16] test_math failed (5 errors, 33 failures)
    

    followed by a number of lines describing the failed tests.
    Actually, the cause of all these errors is inside the implementation of the fma() math function.
    This is an "hystorical" bug of Cygwin because NEWLIB provides a very minimalist implementation of this function and, for this reason, it doesn't guarantee the precision and it doesn't even provides a software replacement for this task:

    https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libm/common/s_fma.c

    I have seen that there is a macro called UNRELIABLE_FMA inside Modules\mathmodule.c.
    I tried to activate this macro with a quick hack and the number of failures decreased from 33 to 20.
    As you can see, it is still failing elsewhere, the above macro fixed some but not all the issues.
    This happens because the fma() is used also for implementing other math functions provided by LIBM.
    Affected functions are:

    • fma()
    • pow()
    • log()
    • log2()

    So, there is not much that is it could be done here, on the source code of Python.
    However, besides the obvious solution of fixing that function inside LIBM, a possible way for fixing this malfunction is using a function from another C library.

    At the end, Cygwin still runs on top of Windows.
    And Windows has its own DLL libraries for providing C functions, including the math ones.
    The fma() is not provided by MSVCRT, but it could be get from UCRT, as well as all other affected math functions.
    The UCRT is available on all versions of Windows supported by Cygwin and it can be made available even on Windows XP by installing the Microsoft Visual C++ Redistributable.
    So, I did a quick patch for testing and I imported those library functions from UCRT.
    As result, all mathematical tests have been executed successfully.
    See here my change:

    diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
    index 6b7fc00..a83d8ea 100644
    --- a/Modules/mathmodule.c
    +++ b/Modules/mathmodule.c
    @@ -114,6 +114,81 @@ dl_sum(double a, double b)
    
     #ifndef UNRELIABLE_FMA
    
    +#ifdef __CYGWIN__
    +
    +#define WIN32_LEN_AND_MEAN
    +#define NOGDI
    +#include <windows.h>
    +
    +#define CRT_NAME "ucrtbase"
    +#define crt_abi __attribute__((ms_abi))
    +
    +typedef double (crt_abi *crt_fma_t)(double, double, double);
    +typedef double (crt_abi *crt_pow_t)(double, double);
    +typedef double (crt_abi *crt_log_t)(double);
    +typedef double (crt_abi *crt_log2_t)(double);
    +
    +static void *crt_get_math_proc_ptr(const char *function_name)
    +{
    +    HMODULE crt_handle = GetModuleHandleA(CRT_NAME);
    +
    +    if (crt_handle) {
    +        return (void *)GetProcAddress(crt_handle, function_name);
    +    }
    +    return NULL;
    +}
    +
    +static double crt_fma(double a, double b, double c)
    +{
    +    crt_fma_t crt_fma = (crt_fma_t)crt_get_math_proc_ptr("fma");
    +
    +    if (crt_fma) {
    +        return crt_fma(a, b, c);
    +    }
    +    return fma(a, b, c);
    +}
    +
    +static double crt_pow(double a, double b)
    +{
    +    crt_pow_t crt_pow = (crt_pow_t)crt_get_math_proc_ptr("pow");
    +
    +    if (crt_pow) {
    +        return crt_pow(a, b);
    +    }
    +    return pow(a, b);
    +}
    +
    +static double crt_log(double a)
    +{
    +    crt_log_t crt_log = (crt_log_t)crt_get_math_proc_ptr("log");
    +
    +    if (crt_log) {
    +        return crt_log(a);
    +    }
    +    return log(a);
    +}
    +
    +static double crt_log2(double a)
    +{
    +    crt_log2_t crt_log2 = (crt_log2_t)crt_get_math_proc_ptr("log2");
    +
    +    if (crt_log2) {
    +        return crt_log2(a);
    +    }
    +    return log2(a);
    +}
    +
    +#undef fma
    +#undef pow
    +#undef log
    +#undef log2
    +#define fma crt_fma
    +#define pow crt_pow
    +#define log crt_log
    +#define log2 crt_log2
    +
    +#endif
    +
     static DoubleLength
     dl_mul(double x, double y)
     {
    

    As you can see, it is just a draft and there are surely better ways for optimizing it, perhaps by loading the pointer to functions only once and falling back to the ones provided by LIBM if they are not found for any reason, or by adding an additional crt_errno() if an error condition needs to be detected (which is not needed at the time of writing).

    After running the test, this is the result on screen:

    $ ./python.exe -m test -v test_math
    == CPython 3.16.0a0 (heads/main-dirty:a5cb7c3, May 24 2026, 14:39:47) [GCC 13.4.0]
    == CYGWIN_NT-10.0-26200-3.6.9-1.x86_64-x86_64-64bit-WindowsPE little-endian
    == Python build: release shared
    == cwd: /home/carlo/packages/python/cygwin/build/test_python_worker_1617æ
    == CPU count: 16
    == encodings: locale=UTF-8 FS=utf-8
    == resources: all test resources are disabled, use -u option to unskip tests
    
    Using random seed: 1958964126
    0:00:00 load avg: 3.92 Run 1 test sequentially in a single process
    0:00:00 load avg: 3.92 [1/1] test_math
    test_fma_infinities (test.test_math.FMATests.test_fma_infinities) ... ok
    test_fma_nan_results (test.test_math.FMATests.test_fma_nan_results) ... ok
    test_fma_overflow (test.test_math.FMATests.test_fma_overflow) ... ok
    test_fma_single_round (test.test_math.FMATests.test_fma_single_round) ... ok
    test_fma_zero_result (test.test_math.FMATests.test_fma_zero_result) ... ok
    test_random (test.test_math.FMATests.test_random) ... ok
    test_asymmetry (test.test_math.IsCloseTests.test_asymmetry) ... ok
    test_decimals (test.test_math.IsCloseTests.test_decimals) ... ok
    test_eight_decimal_places (test.test_math.IsCloseTests.test_eight_decimal_places) ... ok
    test_fractions (test.test_math.IsCloseTests.test_fractions) ... ok
    test_identical (test.test_math.IsCloseTests.test_identical) ... ok
    test_identical_infinite (test.test_math.IsCloseTests.test_identical_infinite) ... ok
    test_inf_ninf_nan (test.test_math.IsCloseTests.test_inf_ninf_nan) ... ok
    test_integers (test.test_math.IsCloseTests.test_integers) ... ok
    test_near_zero (test.test_math.IsCloseTests.test_near_zero) ... ok
    test_negative_tolerances (test.test_math.IsCloseTests.test_negative_tolerances) ... ok
    test_zero_tolerance (test.test_math.IsCloseTests.test_zero_tolerance) ... ok
    testAcos (test.test_math.MathTests.testAcos) ... ok
    testAcosh (test.test_math.MathTests.testAcosh) ... ok
    testAsin (test.test_math.MathTests.testAsin) ... ok
    testAsinh (test.test_math.MathTests.testAsinh) ... ok
    testAtan (test.test_math.MathTests.testAtan) ... ok
    testAtan2 (test.test_math.MathTests.testAtan2) ... ok
    testAtanh (test.test_math.MathTests.testAtanh) ... ok
    testCbrt (test.test_math.MathTests.testCbrt) ... ok
    testCeil (test.test_math.MathTests.testCeil) ... ok
    testConstants (test.test_math.MathTests.testConstants) ... ok
    testCopysign (test.test_math.MathTests.testCopysign) ... ok
    testCos (test.test_math.MathTests.testCos) ... ok
    testCosh (test.test_math.MathTests.testCosh) ... ok
    testDegrees (test.test_math.MathTests.testDegrees) ... ok
    testDist (test.test_math.MathTests.testDist) ... ok
    testExp (test.test_math.MathTests.testExp) ... ok
    testExp2 (test.test_math.MathTests.testExp2) ... ok
    testFabs (test.test_math.MathTests.testFabs) ... ok
    testFloor (test.test_math.MathTests.testFloor) ... ok
    testFmod (test.test_math.MathTests.testFmod) ... ok
    testFrexp (test.test_math.MathTests.testFrexp) ... ok
    testFsum (test.test_math.MathTests.testFsum) ... ok
    testGcd (test.test_math.MathTests.testGcd) ... ok
    testHypot (test.test_math.MathTests.testHypot) ... ok
    testHypotAccuracy (test.test_math.MathTests.testHypotAccuracy) ... ok
    testIsfinite (test.test_math.MathTests.testIsfinite) ... ok
    testIsinf (test.test_math.MathTests.testIsinf) ... ok
    testIsnan (test.test_math.MathTests.testIsnan) ... ok
    testIsnormal (test.test_math.MathTests.testIsnormal) ... ok
    testIssubnormal (test.test_math.MathTests.testIssubnormal) ... ok
    testLdexp (test.test_math.MathTests.testLdexp) ... ok
    testLdexp_denormal (test.test_math.MathTests.testLdexp_denormal) ... ok
    testLog (test.test_math.MathTests.testLog) ... ok
    testLog10 (test.test_math.MathTests.testLog10) ... ok
    testLog1p (test.test_math.MathTests.testLog1p) ... ok
    testLog2 (test.test_math.MathTests.testLog2) ... ok
    testLog2Exact (test.test_math.MathTests.testLog2Exact) ... ok
    testModf (test.test_math.MathTests.testModf) ... ok
    testPow (test.test_math.MathTests.testPow) ... ok
    testRadians (test.test_math.MathTests.testRadians) ... ok
    testRemainder (test.test_math.MathTests.testRemainder) ... ok
    testSin (test.test_math.MathTests.testSin) ... ok
    testSinh (test.test_math.MathTests.testSinh) ... ok
    testSqrt (test.test_math.MathTests.testSqrt) ... ok
    testSumProd (test.test_math.MathTests.testSumProd) ... ok
    testTan (test.test_math.MathTests.testTan) ... ok
    testTanh (test.test_math.MathTests.testTanh) ... ok
    testTanhSign (test.test_math.MathTests.testTanhSign) ... ok
    test_exception_messages (test.test_math.MathTests.test_exception_messages) ... ok
    test_exceptions (test.test_math.MathTests.test_exceptions) ... ok
    test_fmax (test.test_math.MathTests.test_fmax) ... ok
    test_fmax_nans (test.test_math.MathTests.test_fmax_nans) ... ok
    test_fmin (test.test_math.MathTests.test_fmin) ... ok
    test_fmin_nans (test.test_math.MathTests.test_fmin_nans) ... ok
    test_inf_constant (test.test_math.MathTests.test_inf_constant) ... ok
    test_input_exceptions (test.test_math.MathTests.test_input_exceptions) ... ok
    test_issue39871 (test.test_math.MathTests.test_issue39871) ... ok
    test_lcm (test.test_math.MathTests.test_lcm) ... ok
    test_log_huge_integer (test.test_math.MathTests.test_log_huge_integer) ... ok
    test_math_dist_leak (test.test_math.MathTests.test_math_dist_leak) ... ok
    test_mtestfile (test.test_math.MathTests.test_mtestfile) ... ok
    test_nan_constant (test.test_math.MathTests.test_nan_constant) ... ok
    test_nextafter (test.test_math.MathTests.test_nextafter) ... ok
    test_prod (test.test_math.MathTests.test_prod) ... ok
    test_signbit (test.test_math.MathTests.test_signbit) ... ok
    test_sumprod_accuracy (test.test_math.MathTests.test_sumprod_accuracy) ... ok
    test_sumprod_extended_precision_accuracy (test.test_math.MathTests.test_sumprod_extended_precision_accuracy) ... skipped "resource 'cpu' is not enabled"
    test_sumprod_stress (test.test_math.MathTests.test_sumprod_stress) ... skipped "resource 'cpu' is not enabled"
    test_testfile (test.test_math.MathTests.test_testfile) ... ok
    test_trunc (test.test_math.MathTests.test_trunc) ... ok
    test_ulp (test.test_math.MathTests.test_ulp) ... ok
    /home/carlo/packages/python/cpython/Lib/test/mathdata/ieee754.txt
    Doctest: ieee754.txt ... ok
    
    ----------------------------------------------------------------------
    Ran 89 tests in 4.454s
    
    OK (skipped=2)
    0:00:05 load avg: 3.88 [1/1] test_math passed
    
    == Tests result: SUCCESS ==
    
    1 test OK.
    
    Total duration: 5.2 sec
    Total tests: run=89 skipped=2
    Total test files: run=1/1
    Result: SUCCESS
    

    However... in my personal opinion, it would be better to fix LIBM, which would make the problem solved at the roots and it would be nice to have a direct support to FMA3 and FMA4 and a software implementation as fallback.
    In that case, it must be also accepted the fact that older versions of Cygwin won't be able to execute the testsuite successfully, but this is quite obvious.

    I'm providing this report as a reference for the Enhance Cygwin support topic.

    EDIT: in my opinion, hypot() function is fine.
    The tests were failing because the function to fail was sqrt() since it is a subset of the pow() function.

  31. vstinner commented on May 28, 2026

    @vstinner
    MemberAuthor

    Hum. IMO this math patch is a little too big. Also calling GetModuleHandleA() and GetProcAddress() at each function call is inefficient. I suggest you reporting the issue to newlib bug tracker instead.

  32. vstinner commented on May 28, 2026

    @vstinner
    MemberAuthor

    @carlo-bramini: So I'm now curious. How are you using Python in Cygwin? Do you use Python to build other packages? Or for something else? You may share your experience at https://discuss.python.org/t/enhance-cygwin-support/107537.

  33. vstinner commented on Jun 18, 2026

    @vstinner
    MemberAuthor

    I'm done with Cygwin enhancements. I summarized recent changes on https://discuss.python.org/t/enhance-cygwin-support/107537. I close the issue. For further work, you can open new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions