Title: [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 · GitHub
Open Graph Title: [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
X Title: [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
Description: 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 exec...
Open Graph Description: 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 PyInstal...
X Description: 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 PyInstal...
Opengraph URL: https://github.com/python/cpython/issues/160627
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[macOS x86_64, python >= 3.14] Process hangs when importing ctypes from embedded interpreter in a x86_64 macOS executable with enabled hardened runtime","articleBody":"The addition of early [`ffi_closure_alloc()` call to execution/initialization of the `_ctypes` extension](https://github.com/python/cpython/blob/v3.14.8/Modules/_ctypes/_ctypes.c#L6398) in python 3.14.0 (https://github.com/python/cpython/commit/04d4aacaacbe26146e9b5ff6b0043f86f3c543d4 / https://github.com/python/cpython/pull/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).\n\nNamely, 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:\n\n``` \n2026-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.\n```\n\nAt PyInstaller, we've previously observed this issue with python packages that use `cffi` (e.g., `PyOpenSSL` in https://github.com/pyinstaller/pyinstaller/issues/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`. \n\nThe 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.\n\nWe have now received a report of it happening simply by switching from python 3.13 to 3.14 (https://github.com/pyinstaller/pyinstaller/issues/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.\n\nThe 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 https://github.com/libffi/libffi/issues/1032.\n\nSo 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.\n\nAs https://github.com/python/cpython/pull/131633 seems to have been trying to address an issue in free-threaded python builds (https://github.com/python/cpython/issues/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.","author":{"url":"https://github.com/rokm","@type":"Person","name":"rokm"},"datePublished":"2026-10-24T22:37:39Z","url":"https://github.com/python/cpython/issues/160627"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f0138864-38c3-cfee-9d64-f2a06cafe512 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B156:380435:9775AA:BF0657:6B021B6F |
| html-safe-nonce | 840357bd8efbc7bbdf1510123db55c3ceacebf5e1ec2f863a9e674aba6c50727 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTU2OjM4MDQzNTo5Nzc1QUE6QkYwNjU3OjZCMDIxQjZGIiwidmlzaXRvcl9pZCI6IjcwMjQzNTI5ODc4NzEwNTg3OTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a27d662146744df03be1c0194cb5a4cd1c7c6716797dcc37b7f8725307022704 |
| hovercard-subject-tag | issue:6018363715 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/160627/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f0b0e61da8fdddd697903c2612188d735ca4fbfc4a830fe0d5f00b4f7f46a419/python/cpython/issues/160627 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f0b0e61da8fdddd697903c2612188d735ca4fbfc4a830fe0d5f00b4f7f46a419/python/cpython/issues/160627 |
| og:image:alt | 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 PyInstal... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rokm |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width