Skip to main content

Multiprocessing compatible memory leak debugger inspired by dozer/dowser

Project description

PyLoot

PyLoot is a memory leak detector based on Dozer and vprof with added support for process based server workloads.

This project is in active development and may contain bugs or otherwise work in ways not expected or intended.

Installation

$ pip install pyloot

Usage

from pyloot import PyLoot
loot = PyLoot()


"""
Collect objects still in `gc.get_objects` after a call to `gc.collect`.
"""
loot.collect_objects()

"""
Collecting data in a background thread every 30 seconds.

If gevent is detected, gevent.threadpool.spawn is used.
Otherwise, threading.Thread is used.
"""
loot.start()

"""
Return a WSGI compatible application serving the PyLoot remote backend and
and the website.
:return: ::class::`PyLootServer`
"""
loot.get_wsgi()

Running embedded

Starlette/FastApi/ASGI

from pyloot import PyLoot
from fastapi import FastAPI
from starlette.applications import Starlette
from starlette.middleware.wsgi import WSGIMiddleware

app = FastAPI()  # or Starlette()

pyloot = PyLoot()
app.on_event("startup")(pyloot.start)
app.mount("/_pyloot", WSGIMiddleware(pyloot.get_wsgi()))

Flask/WSGI

from pyloot import PyLoot
from flask import Flask
from werkzeug.middleware.dispatcher import DispatcherMiddleware

app = Flask(__name__)

pyloot = PyLoot()
app.on_before_first_request(pyloot.start)

app = DispatcherMiddleware(app, {
    '/_pyloot': pyloot.get_wsgi()
})

Running in remote mode (multi-process servers)

# Embedded code
from pyloot import PyLoot
...
pyloot = PyLoot(host="127.0.0.1", port=8030)
...
# Start the remote server
$ pyloot --help
usage: pyloot [-h HOST] [-p PORT] [--help]

optional arguments:
-h HOST, --host HOST  Host to listen on. (Default: 0.0.0.0)
-p PORT, --port PORT  Port to listen on. (Default: 8030)
--help                show this help message and exit

Bypass the multiprocessing check

If pyloot detects it is running in a multiprocessing environment with an inmemory backend it will refuse to serve the webpages/requests.

The WSGIMiddleware of starlette sets environ["wsgi.multiprocess"]=True regardless of the server. This can by bypassed with a wrapper use with caution:

pyloot = PyLoot()

def pyloot_wrapper(wsgi_environ, start_response):
    pyloot_environ = wsgi_environ.copy()
    pyloot_environ["wsgi.multiprocess"] = False
    wsgi = pyloot.get_wsgi()
    return wsgi(pyloot_environ, start_response)

app.mount("/_pyloot", WSGIMiddleware(pyloot_wrapper))

Screenshots

View history of object counts by object group:

history screenshot

Modify history page size

history screenshot

Search history page

history screenshot

View objects by group

objects by group

Modify objects fetch size

objects by group

Modify objects page size

objects by group

View an object, its attributes, repr, children, and parents

view and object

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyloot-0.0.3.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyloot-0.0.3-py3-none-any.whl (184.2 kB view details)

Uploaded Python 3

File details

Details for the file pyloot-0.0.3.tar.gz.

File metadata

  • Download URL: pyloot-0.0.3.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5

File hashes

Hashes for pyloot-0.0.3.tar.gz
Algorithm Hash digest
SHA256 bb1c4cbfa90502b5d837916fabae5396d1fc678c30e3c7a70c4ce1b324f32bb9
MD5 c896e188aa268cd3bc311272df9d34f1
BLAKE2b-256 04dacad00441a6e98e4c73e3000a37ea11df93684ade9690a8e37d1e523c67a7

See more details on using hashes here.

File details

Details for the file pyloot-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyloot-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 184.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5

File hashes

Hashes for pyloot-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e869b16fcb1b72563412aefcb2b4469e28e70f3c8cdc86d2509d2ec6b2c18499
MD5 0f05f4b4a4919cb2d2446d41cee837b0
BLAKE2b-256 aed73bfe0c6dc058993311e0a04184ce60efa78c29e83d18e05eac662943b569

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page