Skip to content

fix: Improve functools.partial as stream subscriber - #6970

Closed
hoxbro wants to merge 2 commits into
mainfrom
fix_weakref
Closed

fix: Improve functools.partial as stream subscriber#6970
hoxbro wants to merge 2 commits into
mainfrom
fix_weakref

Conversation

@hoxbro

@hoxbro hoxbro commented Jul 24, 2026

Copy link
Copy Markdown
Member

Description

Fixes #6945

_WeakSubscriber now unwrap functools.partial down to the bound method, hold a WeakMethod to it, and store the partial's args/kwargs to reapply on call.

Also pin a strong reference to the subscriber on the document via on_session_destroyed so it survives while displayed and is released when the session ends.

AI Disclosure

Tool & Model: Claude Code:claude-opus-4-8
Usage: 1) Add to make an unwrap of functool.partial to remove the weakref. 2) Make a on_session_destroyed to strong pin it.

  • I have tested all AI-generated content in my PR.
  • I take responsibility for all AI-generated content in my PR.

Checklist

  • Pull request title follows the conventional format
  • Tests added and are passing
  • Added documentation

hoxbro added 2 commits July 24, 2026 10:47
`_WeakSubscriber` previously stored a weak reference to the `partial`
object itself, which -- being a temporary with no other strong reference
-- was collected immediately, so the subscriber never fired (#6945).

Instead unwrap the partial down to the underlying bound method, hold a
`WeakMethod` to it (keeping the memory-leak fix of #6934 intact) and
store the partial's bound args/kwargs separately, reconstructing the call
on trigger. The subscriber hash now identifies the bound method plus the
bound arguments (by id) so distinct partials over the same method are not
collapsed by `unique_iterator`.

Assisted-by: Claude Code:claude-opus-4-8
Method subscribers are held weakly so their bound object can be garbage
collected once a session ends (#6934). When the object is only reachable
through the subscription -- as with a `pn.viewable.Viewer` app whose
instance Panel does not retain -- it is collected immediately and the
subscriber never fires (#6945).

Pin a strong reference to the subscriber on the current session's
document via `on_session_destroyed`, so it stays alive while the plot is
displayed and is released when the session is destroyed. Outside a served
session there is no document and the weak reference is used as-is.

Assisted-by: Claude Code:claude-opus-4-8
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.35%. Comparing base (a06808f) to head (33279a7).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6970   +/-   ##
=======================================
  Coverage   89.34%   89.35%           
=======================================
  Files         344      344           
  Lines       74664    74721   +57     
=======================================
+ Hits        66710    66767   +57     
  Misses       7954     7954           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hoxbro hoxbro changed the title fix: Support functools.partial as stream subscribers fix: Imrpove functools.partial as stream subscriber Jul 24, 2026
@hoxbro hoxbro changed the title fix: Imrpove functools.partial as stream subscriber fix: Improve functools.partial as stream subscriber Jul 24, 2026
@hoxbro hoxbro added this to the 1.23.2 milestone Jul 31, 2026
@hoxbro hoxbro closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Regression] Stream subscribers based on partial functions no longer work

1 participant