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 →
py-spy top --pid <pid>to see which functions are consuming time right now.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).py-spy record -o profile.svg --pid <pid> --duration 60for a flame graph.- 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.
More on Automation scripting & CLI design
Your team has a 300-line Bash script that parses JSON with `jq`, loops over AWS accounts and retries with `sleep`. It breaks every month. Do you rewrite it in Python?BeginnerA colleague's script deletes files older than 30 days from `/var/log/app`. You are asked to review it before it goes into cron. What do you look for?IntermediateYou need a script that ops engineers run from laptops and that CI runs nightly. How do you design its interface?IntermediateA script reads a 15 GB access log to count 5xx errors per endpoint, and the box runs out of memory. How do you fix it?BeginnerYou must run the same Python automation on 40 servers that have Python 3.6, 3.9 and 3.12. What do you do?IntermediateA cron job that runs a Python script fails silently. Nobody noticed for two weeks. How do you make sure that never happens again?Intermediate