Обсуждение: [PATCH] pl: fix can not build free-thread for plpython extension like 3.14t
Hi dear hackers:
This patch fix can not build plpython for free-thread python like python3.14t
which 3.14t is maintain in cpython team
for the doc: https://github.com/python/cpython/blob/1857a40807daeae3a1bf5efb682de9c9ae6df845/Doc/howto/free-threading-extensions.rst#building-extensions-for-the-free-threaded-build
which 3.14t is maintain in cpython team
for the doc: https://github.com/python/cpython/blob/1857a40807daeae3a1bf5efb682de9c9ae6df845/Doc/howto/free-threading-extensions.rst#building-extensions-for-the-free-threaded-build
it needs to open the py_limited_api for free-thread build
Thanks
Hong Yi
Thanks
Hong Yi
Вложения
=?UTF-8?B?5rSq5LyK?= <zouzou0208@gmail.com> writes: > This patch fix can not build plpython for free-thread python like > python3.14t We've gone to fairly considerable trouble to switch to using Python's limited API, for reasons described here: https://www.postgresql.org/message-id/ee410de1-1e0b-4770-b125-eeefd4726a24@eisentraut.org I don't see why we should abandon that for the convenience of somebody's evidently-nonstandard Python build. The proposed patch also breaks the header isolation that the separate plpython_system.h header is meant to maintain. Arguably we should have #define'd Py_LIMITED_API inside plpython_system.h, not where it is. But I don't feel a need to mess with that without a far better argument for why we should change this at all. regards, tom lane
Hi
I understand the reason for using Py_LIMITED_API, and python 3.14t is a standard build from cpython team.
link: https://docs.python.org/3/whatsnew/3.14.html#whatsnew314-free-threaded-now-supported
It seems the only way to build plpython for free-thread python is to use Py_LIMITED_API, otherwise it fails to build.
Thanks
Hong Yi
I understand the reason for using Py_LIMITED_API, and python 3.14t is a standard build from cpython team.
link: https://docs.python.org/3/whatsnew/3.14.html#whatsnew314-free-threaded-now-supported
It seems the only way to build plpython for free-thread python is to use Py_LIMITED_API, otherwise it fails to build.
Thanks
Hong Yi
On Fri, Jan 16, 2026 at 12:01 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
洪伊 <zouzou0208@gmail.com> writes:
> This patch fix can not build plpython for free-thread python like
> python3.14t
We've gone to fairly considerable trouble to switch to using Python's
limited API, for reasons described here:
https://www.postgresql.org/message-id/ee410de1-1e0b-4770-b125-eeefd4726a24@eisentraut.org
I don't see why we should abandon that for the convenience of
somebody's evidently-nonstandard Python build.
The proposed patch also breaks the header isolation that
the separate plpython_system.h header is meant to maintain.
Arguably we should have #define'd Py_LIMITED_API inside
plpython_system.h, not where it is. But I don't feel a need
to mess with that without a far better argument for why
we should change this at all.
regards, tom lane
=?UTF-8?B?5rSq5LyK?= <zouzou0208@gmail.com> writes:
> I understand the reason for using Py_LIMITED_API, and python 3.14t is a
> standard build from cpython team.
AIUI, the "limited API" was devised by the Python community as an
API/ABI subset that they are prepared to guarantee holds stable
for every Python 3.x release, full stop. I think you're going
to have a hard time convincing us that there is anything standard
about a Python variant that can't handle client code built against
that API.
regards, tom lane
Got your point and make sense thank you very much.
Tom Lane <tgl@sss.pgh.pa.us>于2026年1月16日 周五12:43写道:
洪伊 <zouzou0208@gmail.com> writes:
> I understand the reason for using Py_LIMITED_API, and python 3.14t is a
> standard build from cpython team.
AIUI, the "limited API" was devised by the Python community as an
API/ABI subset that they are prepared to guarantee holds stable
for every Python 3.x release, full stop. I think you're going
to have a hard time convincing us that there is anything standard
about a Python variant that can't handle client code built against
that API.
regards, tom lane
I tried to investigate this by installing python314-freethreading from
MacPorts on a handy Mac machine. I got this note during install:
python314-freethreading has the following notes:
Python with free threading has a different ABI and is thus
incompatible with extension modules built for the standard ABI.
and then this while trying to build PG:
/opt/local/Library/Frameworks/Python.framework/Versions/3.14t/include/python3.14t/Python.h:52:4: error: "The limited
APIis not currently supported in the free-threaded build"
So you're right that it's broken. But I can only read this in one
of two ways:
1. The free-threaded build is not actually meant to be production
ready at this point,
or
2. The limited API's promise of API/ABI stability is a lie.
I prefer explanation #1. But I do not think people using Postgres
are particularly interested in development branches of Python, and if
they are, they can surely adjust the Postgres source for themselves.
It would not serve our own project's goals to ship Postgres builds
that are incompatible with the standard limited API.
regards, tom lane
Re: [PATCH] pl: fix can not build free-thread for plpython extension like 3.14t
От
Peter Eisentraut
Дата:
On 16.01.26 06:24, Tom Lane wrote: > So you're right that it's broken. But I can only read this in one > of two ways: > > 1. The free-threaded build is not actually meant to be production > ready at this point, > or > 2. The limited API's promise of API/ABI stability is a lie. > > I prefer explanation #1. But I do not think people using Postgres > are particularly interested in development branches of Python, and if > they are, they can surely adjust the Postgres source for themselves. > It would not serve our own project's goals to ship Postgres builds > that are incompatible with the standard limited API. I don't think there is an expectation that there will be ABI compatibility between free-threaded and normal builds; that's why they put the "t" in the version number to call that out. So I don't think there is a contradiction here. If you're on a normal build, you can opt into the ABI stability offer (or not), if you're on a free-threaded build, you don't have that option (yet). So the proposed patch seems valid, maybe up to some header include reshuffling. But what's not clear to me is whether the PL/Python C code is ready to be run under a free-threaded interpreter. I didn't see any way for an extension to be opt into being run under this model, so I guess they expect that most code will be fine by now. (I suppose you can opt out by testing Py_GIL_DISABLED.) If PL/Python were a trusted PL, I would definitely be very concerned; now I'm only somewhat concerned. ;-)