GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [macOS x86_64, python >= 3.14] Process hangs when importing ctypes from embedded interpreter in a x86_64 macOS executable with enabled hardened runtime · Issue #160627 · python/cpython

[macOS x86_64, python >= 3.14] Process hangs when importing ctypes from embedded interpreter in a x86_64 macOS executable with enabled hardened runtime #160627

New issue
Copy link
New issue
Copy link
Closed as duplicate
Closed as duplicate
[macOS x86_64, python >= 3.14] Process hangs when importing ctypes from embedded interpreter in a x86_64 macOS executable with enabled hardened runtime#160627
Copy link
Labels
OS-macextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@rokm
rokm
opened on Oct 24, 2026
Issue body actions

The addition of early ffi_closure_alloc() call to execution/initialization of the _ctypes extension in python 3.14.0 (04d4aac / #131633) has exacerbated the problem that embedders (such as PyInstaller) encounter on macOS with x86_64 executables that have been codesigned with enabled hardened runtime (which is a requirement for app notarization in Apple Store).

Namely, when such executable (running either natively on an intel Mac, or under Rosetta on an arm64 Mac) ends up calling ffi_closure_alloc(), the process hangs, and the system log shows continuous stream of error messages like this one:

2026-10-20 09:48:59.486398-0700 0x6afb Error 0x0 0 0 kernel: (AppleMobileFileIntegrity) Library Validation failed: Rejecting '/private/var/folders/7c/49675rcx2nb0lwjms_6wmdpr0000gs/T/ffiiyZPuH' (Team ID: none, platform: no) for process 'dangerzone(3322)' (Team ID: 94ZZGGGJ3W, platform: no), reason: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.

At PyInstaller, we've previously observed this issue with python packages that use cffi (e.g., PyOpenSSL in pyinstaller/pyinstaller#8099); and presumably it would also happen with code that uses ctypes and ends up in a codepath that ends up calling ffi_closure_alloc, for example in PyCFuncPtr_new.

The issue does not affect arm64 executables, and the work-around for x86_64 is to enable com.apple.security.cs.allow-unsigned-executable-memory entitlement when signing the executable / app bundle.

We have now received a report of it happening simply by switching from python 3.13 to 3.14 (pyinstaller/pyinstaller#9554). I've traced the problem to import of ctypes (and subsequently the afore-mentioned early ffi_closure_alloc() call in _ctypes), which happens during bootstrap phase of a PyInstaller-frozen python application; so it is guaranteed to happen with python >= 3.14 and with hardened runtime enabled, regardless of how ctypes is actually used, and requires the entitlement as a work-around.

The true cause of the problem is a bug in libffi; in x86_64 codepath it tries to mmap an empty temporary file with PROT_EXEC, which fails due to hardened runtime and file not being signed, and leads to an endless retry loop - see libffi/libffi#1032.

So strictly speaking, this is not a bug in CPython. However, in the grander scheme of things, with Apple dropping support for Intel Macs, even if libffi fixes the problem on their side, the remaining Intel Macs are unlikely to see the fix; the official python builds from python.org seem to be using system-provided copy of libffi (/usr/lib/libffi.dylib, which would have to be updated by Apple), and both Homebrew and Anaconda have also dropped support for x86_64 on macOS.

As #131633 seems to have been trying to address an issue in free-threaded python builds (#128485), I was wondering if it would be possible to put the early ffi_closure_alloc call under ifdefs so that it is omitted for regular (non-free-threaded) python builds on x86_64 macOS? This would mitigate the issue for embedders who still want to support Intel Macs and use latest versions of python. If it is not possible (or worth the hassle), then hopefully this issue report can nudge them in the right direction with the entitlement-based work-around.

Activity

  1. NekoAsakura
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    OS-mac
    topic-ctypes
    on Oct 25, 2026
  2. apyrgio commented on Oct 27, 2026

    @apyrgio
    apyrgio
    on Oct 27, 2026
    More actions

    Btw, here's a a related bug report regarding the same code path in ctypes: #135893

  3. ZeroIntensity commented on Nov 12, 2026

    @ZeroIntensity
    ZeroIntensity
    on Nov 12, 2026
    Member
    More actions

    Yeah, this has the same root cause as #135893. Let's close this in favor of that one. I'll look into a fix.

  4. ZeroIntensity
    closed this as a duplicateof Importing ctypes results in extra open libffi file descriptor since 3.14 #135893 on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-macextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.