{"id":13468628,"url":"https://github.com/khamidou/lptrace","last_synced_at":"2026-04-09T19:03:09.447Z","repository":{"id":12262801,"uuid":"70874657","full_name":"khamidou/lptrace","owner":"khamidou","description":"Trace any Python program, anywhere!","archived":false,"fork":false,"pushed_at":"2018-10-26T07:37:03.000Z","size":27,"stargazers_count":699,"open_issues_count":7,"forks_count":38,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-03-07T17:50:26.053Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://khamidou.com/lptrace/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khamidou.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-14T04:40:20.000Z","updated_at":"2025-02-16T16:42:29.000Z","dependencies_parsed_at":"2022-08-07T06:16:51.028Z","dependency_job_id":null,"html_url":"https://github.com/khamidou/lptrace","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khamidou%2Flptrace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khamidou%2Flptrace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khamidou%2Flptrace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khamidou%2Flptrace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khamidou","download_url":"https://codeload.github.com/khamidou/lptrace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245597254,"owners_count":20641861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T15:01:15.267Z","updated_at":"2025-12-14T12:03:21.164Z","avatar_url":"https://github.com/khamidou.png","language":"Python","readme":"\n# lptrace\n\nlptrace is strace for Python programs. It lets you see in real-time\nwhat functions a Python program is running. It's particularly useful\nto debug weird issues on production.\n\nFor example, let's debug a non-trivial program, the Python SimpleHTTPServer.\nFirst, let's run the server:\n\n```\nvagrant@precise32:/vagrant$ python -m SimpleHTTPServer 8080 \u0026\n[1] 1818\nvagrant@precise32:/vagrant$ Serving HTTP on 0.0.0.0 port 8080 ...\n```\n\nNow let's connect lptrace to it:\n\n```\nvagrant@precise32:/vagrant$ sudo python lptrace -p 1818\n...\nfileno (/usr/lib/python2.7/SocketServer.py:438)\nmeth (/usr/lib/python2.7/socket.py:223)\n\nfileno (/usr/lib/python2.7/SocketServer.py:438)\nmeth (/usr/lib/python2.7/socket.py:223)\n\n_handle_request_noblock (/usr/lib/python2.7/SocketServer.py:271)\nget_request (/usr/lib/python2.7/SocketServer.py:446)\naccept (/usr/lib/python2.7/socket.py:201)\n__init__ (/usr/lib/python2.7/socket.py:185)\nverify_request (/usr/lib/python2.7/SocketServer.py:296)\nprocess_request (/usr/lib/python2.7/SocketServer.py:304)\nfinish_request (/usr/lib/python2.7/SocketServer.py:321)\n__init__ (/usr/lib/python2.7/SocketServer.py:632)\nsetup (/usr/lib/python2.7/SocketServer.py:681)\nmakefile (/usr/lib/python2.7/socket.py:212)\n__init__ (/usr/lib/python2.7/socket.py:246)\nmakefile (/usr/lib/python2.7/socket.py:212)\n__init__ (/usr/lib/python2.7/socket.py:246)\nhandle (/usr/lib/python2.7/BaseHTTPServer.py:336)\nhandle_one_request (/usr/lib/python2.7/BaseHTTPServer.py:301)\n^CReceived Ctrl-C, quitting\nvagrant@precise32:/vagrant$\n```\n\nYou can see that the server is handling the request in real time! After pressing Ctrl-C, the trace is removed and the program\nexecution resumes normally.\n\n# How it works\n\ngdb is an awesome debugger. It lets you attach to any running program, as long as you're root. It\nalso lets you call any C function this program exposes.\n\nWhat's interesting is that among the C functions the Python interpreter exposes,\none function `PyRun\\_SimpleString`, lets you run a single expression of Python code.\n\nWe use this function to ask the Python process to read a temporary file `lptrace` created. This file\ncontains a hook to the `sys.settrace` function, which allows us to get notified whenever a function is\ncalled.\n\nFinally, we need to output the tracing data somewhere. We could do this in the program we're tracing\nbut that wouldn't be very useful. Instead, we write it to a FIFO so that `lptrace` can display it in\nits own window.\n\nThat's about it. I encourage you to read the source --- it's short and pretty simple!\n\n# Running lptrace\n\nlptrace was written to be run on production servers. Because of this,\nyou only need `lptrace` to run the whole program. You can get `lptrace` by installing the `lptrace` [PyPI package](https://pypi.python.org/pypi/lptrace) or simply by downloading the [main source file](https://raw.githubusercontent.com/khamidou/lptrace/master/lptrace).\n\n# Usage\n\n## Tracing a Python program\n\n```\nsudo python lptrace -p \u003cprocess_id\u003e\n```\n\n## Getting a pdb prompt inside a Python program\n\nSometimes it's useful to get a pdb prompt inside a Python program.\nNote that this requires that the Python program you're attaching to\nhas access to stdin.\n\n```\nsudo python lptrace -p \u003cprocess_id\u003e -d\n```\n\n# Requirements\n\nlptrace requires Python 2.7.x and GDB 7.x. It has been tested on Linux\nsuccessfully, and it should run on most recent Unices.\n\n# Issues\n\nPlease open a ticket [here](https://github.com/khamidou/lptrace/issues)\n\n# Security\n\nlptrace is a debugging tool. It uses temporary files, so it may be vulnerable to some race conditions. Caveat emptor!\n\n# Special Thanks\n\nI'd like to thank the [Pyrasite project](http://pyrasite.com/) for coming up with\nthe idea to inject code into a running Python process.\n","funding_links":[],"categories":["Debugging Tools","Python","资源列表","Development Environment","Python Hacks","调试工具","System","Debugging Tools [🔝](#readme)","Awesome Python"],"sub_categories":["调试工具","Debugging and Tracing","Debugging Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhamidou%2Flptrace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhamidou%2Flptrace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhamidou%2Flptrace/lists"}