QA
Senior LevelPython

How do you profile production Python container CPU freezes and kernel system call locking using py-spy and strace without restarting processes?

❓ Interview Prompt: Explain production profiling, `py-spy` (non-intrusive sampling profiler reading process memory), `strace` (system call tracing), and zero-overhead Flamegraphs.

Profiling running production Python containers without pausing execution or modifying source code:

1
'py-spy': Uses Linux 'process_vm_readv' syscall to sample CPython call stacks directly from process RAM without acquiring the GIL or interrupting execution!
2
'strace': Traces low-level OS kernel system calls ('futex', 'epoll_wait', 'read') to detect hanging network sockets or file locks.

Code Implementation Example

bash
# Profile production Python process PID 1234 without pausing execution
py-spy record --pid 1234 --output flamegraph.svg

# Trace blocking kernel system calls on PID 1234
strace -p 1234 -e trace=network,file
💡Profiling production Python containers using py-spy and strace.
🎯 Interview Key Takeaway

Use py-spy to generate production flamegraphs non-intrusively without pausing process execution.

#py-spy#strace#Flamegraph#Production Profiling#Senior
Back to all Python Questions→

More Python Interview Questions

Beginner LevelPython

What is the Python Global Interpreter Lock (GIL) and how does it affect multi-threading?

Beginner LevelPython

What is the difference between a List, Tuple, Set, and Dictionary in Python?

Beginner LevelPython

Why are mutable default arguments (like def func(items=[])) dangerous in Python and how do you fix them?