Python package for garbage collection utilities and memory management
Project description
glon
Python package for garbage collection utilities and memory management.
Overview
The glon package provides comprehensive tools and utilities for working with Python's garbage collector, memory profiling, and cleanup operations. It offers enhanced garbage collection control, memory monitoring, and debugging capabilities.
Features
- Enhanced Garbage Collection: Control and monitor Python's garbage collector with detailed statistics
- Memory Profiling: Track memory usage over time and analyze memory patterns
- Object Tracking: Monitor specific objects using weak references
- Reference Cycle Detection: Find and analyze reference cycles in your code
- Memory Analysis: Comprehensive memory usage analysis and reporting
- Utility Functions: Common garbage collection and memory management tasks
Installation
pip install glon
Development Installation
git clone https://github.com/tom-sapletta/glon.git
cd glon
pip install -e ".[dev]"
Quick Start
Basic Garbage Collection Control
from glon import GarbageCollector
# Create a garbage collector instance
gc_manager = GarbageCollector()
# Force garbage collection
collected = gc_manager.collect()
print(f"Collected {collected} objects")
# Get memory summary
summary = gc_manager.get_memory_summary()
print(summary)
Memory Profiling
from glon import MemoryProfiler
# Create a profiler instance
profiler = MemoryProfiler()
# Take a memory snapshot
profiler.take_snapshot("before_operation")
# Your code here...
data = [list(range(1000)) for _ in range(100)]
# Take another snapshot
profiler.take_snapshot("after_operation")
# Compare snapshots
comparison = profiler.compare_snapshots(0, 1)
print(f"Memory change: {comparison['rss_diff']} bytes")
Memory Monitoring
from glon.utils import monitor_memory_usage
# Monitor memory for 60 seconds
samples = monitor_memory_usage(duration=60, interval=1.0)
for sample in samples:
print(f"Memory: {sample['rss']} bytes, Objects: {sample['objects_count']}")
API Reference
GarbageCollector
Main class for garbage collection control and monitoring.
Methods
enable()- Enable garbage collectiondisable()- Disable garbage collectioncollect(generation=2)- Force garbage collectionget_stats()- Get garbage collection statisticsget_memory_summary()- Get comprehensive memory summary
MemoryProfiler
Class for memory profiling and object tracking.
Methods
take_snapshot(label="")- Take a memory snapshottrack_object(obj, label="")- Track an object with weak referencecompare_snapshots(index1, index2)- Compare two memory snapshotsget_tracked_objects()- Get information about tracked objects
Utility Functions
cleanup_temp_files(pattern="*")- Clean up temporary filesmonitor_memory_usage(duration=60, interval=1.0)- Monitor memory usageforce_garbage_collection(verbose=False)- Force garbage collection on all generationsfind_object_cycles(obj, max_depth=10)- Find reference cyclesanalyze_memory_usage()- Comprehensive memory analysis
Requirements
- Python 3.8+
- psutil>=5.8.0
Development
Running Tests
pytest
Code Formatting
black glon/
Type Checking
mypy glon/
License
Apache License 2.0 - see LICENSE for details.
Contributing
Contributions are welcome! Please read the CONTRIBUTING.md file for details on our code of conduct and the process for submitting pull requests.
Changelog
0.1.0
- Initial release
- Basic garbage collection control
- Memory profiling capabilities
- Utility functions for memory management
License
Apache License 2.0 - see LICENSE for details.
Author
Created by Tom Sapletta - tom@sapletta.com
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
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 glon-0.1.12.tar.gz.
File metadata
- Download URL: glon-0.1.12.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5da9c108f9703b3e32669c34de42fc8560df2a540ca9a2ddfab4ac68498b95df
|
|
| MD5 |
b97150b62f61f14086a4086810cc116d
|
|
| BLAKE2b-256 |
5bef4c141d0c574fcada39439166d34321570d4ff6babded1f81568bdc10ec6f
|
File details
Details for the file glon-0.1.12-py3-none-any.whl.
File metadata
- Download URL: glon-0.1.12-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea12c5f70e675fa037e78569574e431ce9f6492f7ae38f069627146d7ad0722f
|
|
| MD5 |
a448c76e7306cd9900165c61e8271009
|
|
| BLAKE2b-256 |
874173d1f03b37fe6179698f226d8b36698610d4aec98e95ba8f7c99e9894309
|