You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to an upstream CPython bug that landed in 3.11 and whose fix was not backported, any use of wait_for() with a timeout can result in very sporadic and hard to hunt down hangs.
Not submitting a PR for this one yet, since the current version maintains compatibility with 3.10 which does not have Timeout and may warrant a breaking change.
I don't think that fixing this is our responsibility. Python 3.11 is on its way out so replace a core builtin function seems at the same time dangerous and of limited utility, considering that a program might use Psycopg together with other users of wait_for() in other libraries.
Also note that we have just fixed a few cases of mishandling of async cancellation (#1371 chiefly): maybe there's a chance that what was biting was something else? Planning to release 3.3.6 today or tomorrow.
I think it would be safe to just suggest your user to use Python 3.12, which has been around for 3 years already. People who use Python 3.11 should be aware that they are missing at least 3 releases of improvement at this point and this issue is not different.
Also note that we have just fixed a few cases of mishandling of async cancellation (#1371 chiefly): maybe there's a chance that what was biting was something else?
Nope, definitely this issue - wait_for() is genuinely unsafe to use in 3.11 and will eat cancellations.
In a surprising turn of events, working on the optimization in wait_async() in #1416, the use of Event and wait_for() has been dropped in favour of using a Future to coordinate, so the issue you are experiencing should probably be solved with the release 3.3.6 (to be released as soon as #1416 is merged).
Sure, here's a minimal example that just shows the flaw in waiting.wait_async. It'll swallow cancellations in 3.11 and work on all other versions. This will deliver a cancellation in the same frame an I/O wait finishes.
This has not been shown us in the past 3 years that Python 3.11 has been released.
It's very annoying to pin down to psycopg, since it simply discards the cancellation. For most use cases I imagine it wouldn't look like an issue in psycopg at all, since it continues - it would just manifest as a wait on a future that uses psycopg never getting cancelled - stuck forever when you try to clean it up.
In a surprising turn of events, working on the optimization in wait_async() in #1416, the use of Event and wait_for() has been dropped in favour of using a Future to coordinate, so the issue you are experiencing should probably be solved with the release 3.3.6 (to be released as soon as #1416 is merged).
Activity
dvarrazzo commentedon Sep 17, 2026
Hello,
I don't think that fixing this is our responsibility. Python 3.11 is on its way out so replace a core builtin function seems at the same time dangerous and of limited utility, considering that a program might use Psycopg together with other users of
wait_for()in other libraries.Also note that we have just fixed a few cases of mishandling of async cancellation (#1371 chiefly): maybe there's a chance that what was biting was something else? Planning to release 3.3.6 today or tomorrow.
I think it would be safe to just suggest your user to use Python 3.12, which has been around for 3 years already. People who use Python 3.11 should be aware that they are missing at least 3 releases of improvement at this point and this issue is not different.
TkTech commentedon Sep 17, 2026
Nope, definitely this issue -
wait_for()is genuinely unsafe to use in 3.11 and will eat cancellations.Is 3.3.6 dropping 3.11 support?
dvarrazzo commentedon Sep 17, 2026
No, we usually drop old versions support on minor releases, not on bugfix releases.
This has not been shown us in the past 3 years that Python 3.11 has been released. Can you write a test to show it?
dvarrazzo commentedon Sep 18, 2026
In a surprising turn of events, working on the optimization in
wait_async()in #1416, the use ofEventandwait_for()has been dropped in favour of using aFutureto coordinate, so the issue you are experiencing should probably be solved with the release 3.3.6 (to be released as soon as #1416 is merged).TkTech commentedon Sep 19, 2026
Sure, here's a minimal example that just shows the flaw in
waiting.wait_async. It'll swallow cancellations in 3.11 and work on all other versions. This will deliver a cancellation in the same frame an I/O wait finishes.It's very annoying to pin down to psycopg, since it simply discards the cancellation. For most use cases I imagine it wouldn't look like an issue in psycopg at all, since it continues - it would just manifest as a wait on a future that uses psycopg never getting cancelled - stuck forever when you try to clean it up.
Fantastic!