Interview Prep/Python for DevOps/Automation scripting & CLI design

A script runs for 6 hours and you want to know where the time goes without restarting it. How?

AdvancedScenarioAutomation scripting & CLI design
Answer

Situation read → Need live introspection of a running process.

What I'd do →

  1. py-spy top --pid <pid> to see which functions are consuming time right now.
  2. py-spy dump --pid <pid> to see each thread's current stack; repeated dumps show if it is stuck on the same call (a network call with no timeout is the usual culprit).
  3. py-spy record -o profile.svg --pid <pid> --duration 60 for a flame graph.
  4. Next run: add timing logs per phase and a progress counter.

Why → py-spy samples from outside the process with no code changes or restart.

Interview tip → "Six hours" is often a missing timeout or sequential API calls; mention both.

All Python for DevOps questions Roadmap: Python for automation

More on Automation scripting & CLI design