pydebug | Decorators for debugging Python | Code Inspection library
kandi X-RAY | pydebug Summary
kandi X-RAY | pydebug Summary
This is a simple set of utilities which makes it easier to debug Python objects. Pydebug respects Django's config. It checks if the decorator is running within a Django project and DEBUG is set to True. If it's set to False, it simply returns the function.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Initialize a function .
- Calls the decorated function .
- Calls the cleanup method .
- Logs a debug message .
- Sets up the setup .
- Raise a TypeError if func is not callable .
- Return True if self is a subclass of self . func .
- Check if the function is a class .
- Returns True if the function is a function .
pydebug Key Features
pydebug Examples and Code Snippets
from pydebug import PDBDebugger
@PDBDebugger()
def hello_world(a, b):
x = a + b
return (a, b)
from pydebug import PDBDebugger
@PDBDebugger(on_error=True)
def hello_world(a, b):
x = a + b
return (a, b)
from pydebug import Disassembledebug
@DisassembleDebug()
def hello_world(a, b):
x = a + b
return (a, b)
from pydebug import ProfilerDebug
@ProfilerDebug()
def hello_world(a, b):
x = a + b
return (a, b)
Community Discussions
Trending Discussions on pydebug
QUESTION
I am building Python 3.10 from source on Ubuntu 18.04, following instructions from several web links, primarily the Python website (https://devguide.python.org/setup) and RealPython (https://realpython.com/installing-python/#how-to-build-python-from-source-code). I extracted Python-3.10.0.tgz into /opt/Python3.10
. I have three questions.
First, the Python website says to use ./configure --with-pydebug
and RealPython says to use ./configure --enable-optimizations --with-ensurepip=install
. Another source says to include --enable-shared
and --enable-unicode=ucs4
. Which of these is best? Should I use all of those flags?
Second, I currently have Python 3.6 and Python 3.8 installed. They are installed in several directories under /usr
. Following the directions I have seen on the web I am building in /opt/Python3.10. I assume that make altinstall
(the final build step) will take care of installing the build in the usual folders under /usr
, but that's not clear. Should I use ./configure --prefix=directory
although none of the web sources mention doing that?
Finally, how much does --enable-optimizations
slow down the install process?
This is my first time building Python from source, and it will help to clear these things up. Thanks for any help.
...ANSWER
Answered 2021-Nov-13 at 22:52Welcome to the world of Python build configuration! I'll go through the command line options to ./configure
one by one.
--with-pydebug
is for core Python developers, not developers (like you and me) just using Python. It creates debugging symbols and slows down execution. You don't need it.
--enable-optimizations
is good for performance in the long run, at the expense of lengthening the compiling process, possibly by 3-fold (or more), depending on your system. However, it results in faster execution, so I would use it in your situation.
--with-ensurepip=install
is good. You want the most up-to-date version of pip
.
--enable-shared
is maybe not a good idea in your case, so I'd recommend not using it here. Read Difference between static and shared libraries? to understand the difference. Basically, since you'll possibly be installing to a non-system path (/opt/local
, see below) that almost certainly isn't on your system's search path for shared libraries, you'll very likely run into problems down the road. A static build has all the pieces in one place, so you can install and run it from wherever. This is at the expense of size - the python
binary will be rather large - but is great for non-sys admins. Even if you end up installing to /usr/local
, I would argue that static is better/easier than shared.
--enable-unicode=ucs4
is optional, and may not be compatible with your system. You don't need it. ./configure
is smart enough to figure out what Unicode settings are best. This option is left over from build instructions that are quite a few versions out of date.
--prefix
I would suggest you use --prefix=/opt/local
if that directory already exists and is in your $PATH
, or if you know how to edit your $PATH
in ~/.bashrc
. Otherwise, use /usr/local
or $HOME
. /usr/local
is the designated system-wide location for local software installs (i.e., stuff that doesn't come with Ubuntu), and is likely already on your $PATH
. $HOME
is always an option that doesn't require the use of sudo
, which is great from a security perspective. You'll need to add /home/your_username/bin
to your $PATH
if it isn't already present.
QUESTION
When I run cpython with the -X showrefcount
flag on an extension I'm writing, it reports a negative reference count (e.g. [-5538 refs, 13503 blocks]
) when I return None from a function (using the Py-RETURN_NONE
macro).
- The exact count varies between runs, but remains within the same order of magnitude.
- Whatever is happening, it seems to happen slowly; I need to call the extension function approximately 50,000 times before the reference count goes negative.
- If we replace
Py_RETURN_NONE;
withPy_INCREF(Py_None); return Py_None;
, it changes nothing. Indeed, we can seemingly add an arbitrary number ofPy_INCREF(Py_None)
s without affecting the reference count at all. - If we replace
Py_RETURN_NONE;
withreturn Py_None;
and don't increment the reference count, it segfaults (as expected). - If we replace the None return with another value, e.g.
PyLong_FromLong(0);
, the problem vanishes.
What is the cause of this? Related question: why is the reference count not zero after running an empty script?
Minimal Example: build command used for cpython debug build ...ANSWER
Answered 2021-Jun-10 at 20:52The problem was due to the extension having been built using an older version of python, and run using a debug build compiled from the latest version of the source. Extensions not compiled using the stable ABI (and declared as doing so) are not binary compatible across python versions.
[Credit to ead's comment for asking the question that led directly to this solution.]
QUESTION
I'm currently on a cpython guide: https://realpython.com/products/cpython-internals-book/
I will detail what i did and what the problem is. So as it says on the book, i cloned the github :
...ANSWER
Answered 2020-Nov-05 at 18:09I don't have the book and this is my first time editing Python's grammar, but I got it to work.
Build the "regular" Python 3.10 and install to some temporary directory, like
cpython/build/INSTALL
:
QUESTION
I have a project in a conda
environment that runs with python 3.7.7 (on linux). When I recompile the same version of python (3.7.7) and put/replace the executable at the same location, I expect the program to run the same way, but the import fails.
With the original version of python:
...ANSWER
Answered 2020-Sep-27 at 01:16Where did you compiled the new Python? It could be that missing lib librt.so.1
is the culprit for the error message. Is there any chance to install the librt
package (depends on your Linux flavor) and recompile Python.
QUESTION
I am playing around with CPython and trying to understand how a debugger works.
Specifically, I am trying to get the location of the last PyFrameObject
so that I can traverse that and get the Python backtrace.
In the file ceval.c
, line 689 has the definition of the function:
PyObject * PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
What I am interested in getting is the location of f
on the stack. When dumping the binary with dwarfdump
I get that f
is at $rbp-824
, but if I dump the binary with objdump
I get that the location is $rbp-808
- a discrepancy of 16. Also, when debugging with GDB, I get that the correct answer is $rbp-808
like objdump
gives me. Why the discrepancy, and why is dwarfdump
incorrect? What am I not understanding?
How to technically recreate the problem:
Download python-2.7.17.tgz
from Python website. Extract.
I compiled python-2.7.17 from source with debug symbols (./configure --enable-pydebug && make
). Run the following commands on the resulting python
binary:
dwarfdump Python-2.7.17/python
has the following output:
ANSWER
Answered 2020-Apr-02 at 01:50
DW_OP_fbreg -824
: Meaning$rbp-824
It does not mean that. It means, offset -824
from frame base (virtual) register, which is not necessarily (nor usually) equal to $rbp
.
You need to look for DW_AT_frame_base
to know what the frame base in the current function is.
Most likely it's defined as DW_OP_call_frame_cfa
, which is the value of $RSP
just before current function was called, and is equal to $RBP-16
(8 bytes for return address saved by the CALL
instruction, and 8 bytes for previous $RBP
saved by the first instruction of your function).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pydebug
You can use pydebug like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page