pyleak
Detect leaked asyncio tasks, threads, and event loop blocking in Python. Inspired by Go's goleak
Decision gist · record as of 2026-08-14
Yes, if you write asyncio or threaded code and want automated leak detection during testing. The low install friction and clear API make it straightforward to add to test suites. However, verify the license terms first (currently unclear in the metadata), and note that the project is aging—last release was 197 days ago. Not suitable for production monitoring; use it as a development and testing tool.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.9 or later.
- Event loop blocking detection only works in async context; thread detection only in sync context.
- Low install friction with only two lightweight runtime dependencies (exceptiongroup, sniffio).
License · maintenance · safety
(unclear) — License status is unclear; no SPDX identifier or raw license text is available in the package metadata. Verify the actual license before use in proprietary or restricted-license projects.
last release 2026-01-29 (197 days) · last repo commit 2026-01-29 · 403 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 562,550 downloads/mo, #5,987 on PyPI
Alternatives
Verify before relying
pip install pyleak
import asyncio
from pyleak import no_task_leaks
async def main():
async with no_task_leaks():
asyncio.create_task(asyncio.sleep(10))
await asyncio.sleep(0.1)
asyncio.run(main())- Whether the package is suitable for production use or primarily for testing and development
- Actual license terms and any attribution or usage restrictions
- Performance overhead of leak detection in real-world async codebases
What it is and what it does
pyleak is a testing and debugging tool that catches resource leaks in Python async code. It provides three main detectors—no_task_leaks, no_thread_leaks, and no_event_loop_blocking—each usable as a context manager or decorator. When a leak or blocking event is detected, the tool reports it with detailed stack traces showing where the resource was created and where it is currently executing. You configure the response via an action parameter: warn (default, issues ResourceWarning), log (writes to logger), cancel (for tasks only), or raise (throws an exception).
The package is inspired by Go's goleak and targets developers writing asyncio-heavy applications who need to catch unintended resource leaks during testing. It depends on exceptiongroup and sniffio, both lightweight libraries. The tool supports name filtering by exact match or regex pattern for tasks and threads, and optional creation-stack tracking (via monkey-patching) for deeper debugging. It requires Python 3.9 or later.
Use it for
- Detect unintended asyncio tasks left running after a test or function completes
- Catch threads spawned but never properly joined in sync code paths
- Identify blocking calls (e.g., time.sleep) that freeze the event loop during async execution
- Validate cleanup in async context managers and fixture teardown
- Debug resource leaks in long-running async services before deployment
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you write asyncio or threaded code and want automated leak detection during testing.
The low install friction and clear API make it straightforward to add to test suites. However, verify the license terms first (currently unclear in the metadata), and note that the project is aging—last release was 197 days ago. Not suitable for production monitoring; use it as a development and testing tool.
Install
pyleak on PyPI
Before you install
Low install friction with only two lightweight runtime dependencies (exceptiongroup, sniffio). Maintenance status is aging—last release was 197 days ago, though the repository remains active with 403 stars.
Requires Python 3.9 or later. Event loop blocking detection only works in async context; thread detection only in sync context.
License in practice
License status is unclear; no SPDX identifier or raw license text is available in the package metadata. Verify the actual license before use in proprietary or restricted-license projects.
Quickstart
pip install pyleak
import asyncio
from pyleak import no_task_leaks
async def main():
async with no_task_leaks():
asyncio.create_task(asyncio.sleep(10))
await asyncio.sleep(0.1)
asyncio.run(main())
Verify before relying
- Whether the package is suitable for production use or primarily for testing and development
- Actual license terms and any attribution or usage restrictions
- Performance overhead of leak detection in real-world async codebases
Package facts
| License | Not declared unclear |
| Python support | Supports the current Python release >=3.9 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesexceptiongroupsniffio |
| Maintenance | Aging 197 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 562,550 / month, #5,987 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
Evidence: pyleak-0.2.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “asyncio task leak detection”
- pyleakDetects leaked asyncio tasks, threads, and event loop blocking in…
- aiofloProvides an async Python library for controlling and monitoring Flo…
- mozleakExtracts memory leaks from leak log files, primarily for Firefox and…
Give your agent the search over MCP, or paste the wish link into any chat.
More Testing packages
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.
Install it if you write tests for any asyncio-based code.
A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.
Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.
See also aiocop · aiodebug · pytest-threadleak · blockbuster · nest-asyncio2 · mozleak · zthreading · aiorun · unsync · aiomonitor