Skip to content

feat: accept custom backends in set_async_backend - #439

Merged
tlambert03 merged 5 commits into
pyapp-kit:mainfrom
jacopoabramo:feat/custom-async-backend
Oct 6, 2026
Merged

tlambert03 merged 5 commits into
pyapp-kit:mainfrom
jacopoabramo:feat/custom-async-backend

Conversation

@jacopoabramo

Copy link
Copy Markdown
Contributor

Closes #437

  • Add an AsyncBackend protocol and export it from psygnal along with QueueItem
  • Accept an AsyncBackend instance in set_async_backend and return that same instance
  • Raise RuntimeError when setting a custom backend while a different one is set
  • Add close() to TrioBackend, so clear_async_backend closes every backend through close()
  • Annotate EventLike.wait as returning object
  • Document custom backends in the async guide

One nitpick is that a run() method needs to access callback.dereference() and WeakCallback is private so maybe an helper method could shield the need to call it explicitly.

@codspeed

codspeed Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 67 untouched benchmarks


Comparing jacopoabramo:feat/custom-async-backend (03f5986) with main (48aeff1)

Open in CodSpeed

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (48aeff1) to head (03f5986).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #439   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          23       23           
  Lines        2533     2548   +15     
=======================================
+ Hits         2527     2542   +15     
  Misses          6        6           

☔ 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.

@tlambert03 tlambert03 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @jacopoabramo

I'm in favor of this, couple minor nits about what we expose. curious to get your thoughts

Comment thread src/psygnal/_async.py
Comment thread src/psygnal/_async.py Outdated
Comment thread src/psygnal/_async.py Outdated
@jacopoabramo

Copy link
Copy Markdown
Contributor Author

All reasonable. I'll address them asap

@jacopoabramo

Copy link
Copy Markdown
Contributor Author

@tlambert03 done.

I've kept your original suggestion of _AsyncCall but to be perfectly honest since it's used in _weak_callback.py it would make more sense to have it there since _async.py doesn't use it. Up to you really, it's just more for form. I don't think it could cause circular import issues...

@tlambert03

Copy link
Copy Markdown
Member

looks good thanks!

@tlambert03
tlambert03 merged commit 7b28c2a into pyapp-kit:main Oct 6, 2026
40 checks passed
@jacopoabramo
jacopoabramo deleted the feat/custom-async-backend branch October 6, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Accept a custom async backend in set_async_backend

2 participants