Title: Python 3.14 free-threaded support · Issue #2720 · pythonnet/pythonnet · GitHub
Open Graph Title: Python 3.14 free-threaded support · Issue #2720 · pythonnet/pythonnet
X Title: Python 3.14 free-threaded support · Issue #2720 · pythonnet/pythonnet
Description: Tracking issue for free-threaded Python (Py_GIL_DISABLED) support. Companion to the umbrella 3.14 tracker #2610. Why FT is different from a normal GIL build PyObject_HEAD is 16 bytes larger; the refcount is split across ob_ref_local + ob...
Open Graph Description: Tracking issue for free-threaded Python (Py_GIL_DISABLED) support. Companion to the umbrella 3.14 tracker #2610. Why FT is different from a normal GIL build PyObject_HEAD is 16 bytes larger; the re...
X Description: Tracking issue for free-threaded Python (Py_GIL_DISABLED) support. Companion to the umbrella 3.14 tracker #2610. Why FT is different from a normal GIL build PyObject_HEAD is 16 bytes larger; the re...
Opengraph URL: https://github.com/pythonnet/pythonnet/issues/2720
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Python 3.14 free-threaded support","articleBody":"Tracking issue for free-threaded Python (`Py_GIL_DISABLED`) support. Companion to the umbrella 3.14 tracker #2610.\n\n## Why FT is different from a normal GIL build\n\n- `PyObject_HEAD` is 16 bytes larger; the refcount is split across `ob_ref_local` + `ob_ref_shared` and must be read via `Py_REFCNT` (a real exported symbol on 3.14+).\n- Build detection: `sys._is_gil_enabled()` (added in 3.13) returns `False` on FT.\n- The GIL has been silently serialising every pythonnet static cache, lock-free counter, finalizer-thread interaction, and `Reflection.Emit` use site. All of those need explicit synchronisation under FT.\n\n## Hazards in pythonnet (resolved by PR #2721)\n\n| Area | What broke | How it was fixed |\n|---|---|---|\n| Refcount / ABI | Single-offset read | `Py_REFCNT` P/Invoke + `ObjectHeadOffset = 16` for FT |\n| Type-creation race | Duplicate `cache.Add`; partial-type visibility | Two-cache (`cache` + `_inProgressCache`) under `_cacheCreateLock` |\n| GCHandle in `tp_clear`/`tp_dealloc` | Double-free under main-thread + finalizer-thread race | `Interlocked.Exchange` on the slot |\n| `Reflection.Emit` | Concurrent `DefineType` corrupts IL / throws \"Duplicate type name\" | Lock both `CreateDerivedType` and `DelegateManager.GetDispatcher` |\n| Static collections | Plain `Dictionary`/`HashSet`/`List` thread-safety issues | `ConcurrentDictionary` where possible; `Interlocked`/`Volatile` for single-cell state; locks for nested mutation and ordered list semantics |\n| Finalizer-thread / `Py_Finalize` interaction | Stale `ob_ref_local` reads after teardown crash the process | `Runtime._Py_IsFinalizing()` guards on all decref-from-finalizer paths |\n| Chained `ClassDerived.Finalize` IL | Nested Python-derived classes with `__namespace__` chained through emitted `Finalize` methods, queuing the same `__pyobj__` twice → `PyObject_GC_Del` on freed memory | Skip the base-Finalize chain when the base is itself pythonnet-emitted (`IPythonDerivedType`) |\n\nSee PR #2721 for the per-file detail.\n\n## References\n\n- PR: #2721\n- Umbrella 3.14 tracker: #2610\n- CPython PEP 703: https://peps.python.org/pep-0703/\n- CPython 3.14 free-threading docs: https://docs.python.org/3.14/howto/free-threading-extensions.html\n\n","author":{"url":"https://github.com/greateggsgreg","@type":"Person","name":"greateggsgreg"},"datePublished":"2026-05-09T21:58:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/2720/pythonnet/issues/2720"}
| 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:e344eab4-0f7d-93de-93cb-bf3ec4c41993 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E658:6E56C:46B2867:62727EB:6A54E746 |
| html-safe-nonce | 80ee9c9218b139595be64f7f43a69fce20530e5acda516bdff2ae15f635ab590 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjU4OjZFNTZDOjQ2QjI4Njc6NjI3MjdFQjo2QTU0RTc0NiIsInZpc2l0b3JfaWQiOiIzNzM2NTExMjk3NDkzNDYwODA2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9a5afb7565362f9676e4d1d88a069000fe6788c49e06166b193af96022a73faf |
| hovercard-subject-tag | issue:4413945700 |
| 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/pythonnet/pythonnet/2720/issue_layout |
| twitter:image | https://opengraph.githubassets.com/96f8c2704d884256d6d8ea8758a620d78317d09ef3de9329bbdda70afd66b24c/pythonnet/pythonnet/issues/2720 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/96f8c2704d884256d6d8ea8758a620d78317d09ef3de9329bbdda70afd66b24c/pythonnet/pythonnet/issues/2720 |
| og:image:alt | Tracking issue for free-threaded Python (Py_GIL_DISABLED) support. Companion to the umbrella 3.14 tracker #2610. Why FT is different from a normal GIL build PyObject_HEAD is 16 bytes larger; the re... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | greateggsgreg |
| hostname | github.com |
| expected-hostname | github.com |
| None | eae2aab99907699a22d2c8449aa683ca74454fca87211b98f7c7b722086b2839 |
| turbo-cache-control | no-preview |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| 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 | bb1b4ffdc07c66de20ad344214f55df0aa364bd3 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width