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→