skillfed

pyleak

Detect leaked asyncio tasks, threads, and event loop blocking in Python. Inspired by Go's goleak

pyleak v0.2.0 562.5K downloads/30d#5,987 on PyPI403
License unclear AGING released

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

Detects leaked asyncio tasks, threads, and event loop blocking in Python code using context managers or decorators, reporting violations with stack traces.

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

pip

pip install pyleak

uv

uv add pyleak

poetry

poetry add pyleak

Installing pyleak

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.

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())

Requires Python 3.9 or later. Event loop blocking detection only works in async context; thread detection only in sync context.

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 — exceptiongroup, sniffio
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

Keywords: async, asyncio, goleak, leak, pytest, tasks, testing, threads

Tags

asyncio task leak detectionthread leak detection pythonevent loop blocking detectorresource leak testingasyncio testing tools
asyncio-testingresource-leak-detectiondebugging

More Testing packages