Rapid fire: debugging and profiling commands.
AdvancedConceptBest practices & rapid-fire commands
Answer
python -X importtime -c "import cloudaudit.cli" 2>&1 | sort -t'|' -k2 -n | tail # slow imports
python -m cProfile -s cumtime script.py | head -30
py-spy top --pid 1234 # sample a running process, no restart
py-spy dump --pid 1234 # stack of every thread (hung process)
python -X faulthandler script.py # dump traceback on segfault/hang signal
python -m pdb script.py # or breakpoint() in code
PYTHONASYNCIODEBUG=1 python app.py # slow callbacks, unawaited coroutines
py-spy dump is the fastest way to see where a stuck production script is blocked.
More on Best practices & rapid-fire commands
What does a production-quality automation script always include?IntermediateHow do you handle configuration in a Python tool?IntermediateWhat are the most common security mistakes in Python ops code?AdvancedBash or Python for this task: how do you decide?BeginnerRapid fire: set up a project environment from scratch.BeginnerRapid fire: one-liners useful during an incident.Intermediate