Add your description here
Project description
pyleak
Detect leaked asyncio tasks in Python. Inspired by Go's goleak.
Installation
pip install pyleak
Usage
Context Manager
import asyncio
from pyleak import no_task_leaks
async def main():
async with no_task_leaks():
# This will detect any tasks that aren't properly awaited
asyncio.create_task(some_background_work()) # This would be flagged
await asyncio.sleep(0.1)
asyncio.run(main())
Decorator
@no_task_leaks()
async def test_my_function():
await my_async_function()
# Any leaked tasks will be detected when the function exits
Actions
Choose what happens when leaks are detected:
# Warn (default) - issues a ResourceWarning
async with no_task_leaks(action="warn"):
pass
# Log - writes to logger
async with no_task_leaks(action="log"):
pass
# Cancel - cancels the leaked tasks
async with no_task_leaks(action="cancel"):
pass
# Raise - raises TaskLeakError
async with no_task_leaks(action="raise"):
pass
Name Filtering
Only detect tasks matching specific names:
import re
# Exact match
async with no_task_leaks(name_filter="background-worker"):
pass
# Regex pattern
async with no_task_leaks(name_filter=re.compile(r"worker-\d+")):
pass
Testing
Perfect for catching leaked tasks in tests:
import pytest
from pyleak import no_task_leaks
@no_task_leaks(action="raise")
async def test_no_leaked_tasks():
# Test will fail if any tasks are leaked
await my_function_under_test()
class TestMyApp:
async def test_with_context_manager(self):
async with no_task_leaks(action="raise"):
await my_async_operation()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyleak-0.1.0.tar.gz
(18.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyleak-0.1.0.tar.gz.
File metadata
- Download URL: pyleak-0.1.0.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9c6f79781dba05197610c048f14c8bc6cccab0beb257f7caa741cec83d13d1d
|
|
| MD5 |
a8f02a401549242f120c14229c31a7b3
|
|
| BLAKE2b-256 |
7f664621a1aaa5a2c150ea2d283d667a3115cc15ff29ec5d6a2ea8a771e44a89
|
File details
Details for the file pyleak-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyleak-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3e85cdf24f867edaf7f8da68dc532812a23f4dfcf38d6d377621e333e37f1cb
|
|
| MD5 |
ee9467c6d257b22996502b10c45889ed
|
|
| BLAKE2b-256 |
755f09dfdc5154f6d5d1535571861757f18e6494276553fd362ec4d12b5dc70f
|