A convenient function memo to use when you want to enter the debugger if an error occurs when running a Python script.

It is a method to use the debugger of Ipyhoon.core which is stronger than pdb.

set_debugger.py


import sys

def set_debugger_org():
    if not sys.excepthook == sys.__excepthook__:
        from IPython.core import ultratb
        sys.excepthook = ultratb.FormattedTB(call_pdb=True)

def set_debugger_org_frc():
    from IPython.core import ultratb
    sys.excepthook = ultratb.FormattedTB(call_pdb=True)

def set_trace():
    from IPython.core.debugger import Pdb
    Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back)

You can call `set_debugger_org_frc ()` etc. in the main function.

Unfortunately, there are times when it doesn't get into the debugger well.

I was taught by my senior. Thank you.

Recommended Posts

A convenient function memo to use when you want to enter the debugger if an error occurs when running a Python script.
Python Note: When you want to know the attributes of an object
If you want to count words in Python, it's convenient to use Counter.
What to do if you get an error when installing python with pyenv
If you want to make a discord bot with python, let's use a framework
What to do if an error occurs when loading a python project created with poetry into VS Code
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get an error when importing matplotlib in Python (Mac)
Solution when you want to use cv_bridge with python3 (virtualenv)
[Python] If you suddenly want to create an inquiry form
If you want your colleagues to use the same language
When you want to hit a UNIX command on Python
Check the argument type annotation when executing a function in Python and make an error
[Python] When you want to import and use your own package in the upper directory
If you want to put an argument in the closure function and execute it later
If you want to use field names with hyphens when updating firestore data in python
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if you get an Undefined error when trying to use pip with pyenv
[Python] If you create a file with the same name as the module to be imported, an Attribute Error will occur.
[Note] [One-line memo] If you add the -u option to Python, stdout and stderr become unbuffered. Useful when piped to a tee
Write a script in Shell and Python to notify you in Slack when the process is finished
"Cython" tutorial to make Python explosive: When a function on the C ++ side has an overload.
When you want to use multiple versions of the same Python library (virtual environment using venv)
If you want to assign csv export to a variable in python
When you want to save the result of the callback function somewhere
[Python] Explains how to use the format function with an example
Determine if standard output is piped when running a Python script
About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
A memo when using systemd to keep a Python script running as a daemon on CentOS 7 at all times.
If you just want to get the dump file of the server, it was convenient to build an http server
[Django] What to do if an Integrity Error occurs when registering data from the management site to the database
If you want a singleton in python, think of the module as a singleton
[Python] Explains how to use the range function with a concrete example
When you want to use it as it is when using it with lambda memo
Gist repository to use when you want to try a little with ansible
If you want to include awsebcli with CircleCI, specify the python version
[Python] If you want to draw a scatter plot of multiple clusters
What to do if an error occurs when importing numpy with VScode
What to do if you get an error when trying to load mnist
What to do if you get an error when installing Dlib (Ubuntu)
Python: I want to measure the processing time of a function neatly
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
[Python3] Code that can be used when you want to cut out an image in a specific size
[Python3] Code that can be used when you want to change the extension of an image at once
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
Workaround if you get an error when trying to install PySide with pip
Two document generation tools that you definitely want to use if you write python
If you want to make a TODO application (distributed) now using only Python
Use PIL in Python to extract only the data you want from Exif
What to do if a Unicode Encode Error occurs in Sublime Text Python
If an exception occurs in the function, it will be transmitted to the caller 2
[Python] What to check when you get a Unicode Decode Error in Django
If you get a long error when tabbing an interactive shell with Anaconda
If you want to enter the virtual environment with jupyter, nb_conda_kernels is recommended
If an exception occurs in the function, it will be transmitted to the caller 1
What to do if a version error occurs in the selenium Chrome driver
Install the python library when you're not a sudoer (or if you don't want new users to be Sudoer, but you don't mind having the Python Library installed as you like)
If you want to create a Word Cloud.
When you want to update the chrome driver.
I want to use the activation function Mish