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.4.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.4-py3-none-any.whl (184.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyloot-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 eadabc842415773e23474ee1978a396c852d1f56df4ff2000126a5bdab79aca1
MD5 bf262f06b4c8ea6c6d017ea2da93237b
BLAKE2b-256 87dc8c69ab58af5108c4dacec52f4f444db93f604673ff09935ff7c47f816c35

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyloot-0.0.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9255f7d4ff81cfff0a486a486bb92af10b3ef605cbba50648b86d3d8dd038b8e
MD5 f9893ad9893813e64ed48c7d8643eed2
BLAKE2b-256 f83fbc0ef6dcfef6497b5f793487b583c867824fda5f0ed5fc9a604902fa0d8b

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