Troubleshooting & Problem Resolution Flashcards
7 cards from real POC practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Troubleshooting & Problem Resolution flashcards as text
A `StopIteration` exception propagates out of a generator function unexpectedly. What Python version behavior causes this?
Answer: In Python 3.7+, StopIteration raised inside a generator is converted to RuntimeError
PEP 479 (active from Python 3.7) converts `StopIteration` raised inside a generator body into a `RuntimeError` to prevent silent bugs.
You profile a slow script with `cProfile` and find most time is spent in a pure-Python loop. What is the best optimization?
Answer: Replace the loop with a NumPy vectorized operation or a built-in written in C
NumPy operations and built-in functions execute compiled C code, which is orders of magnitude faster than pure-Python loops.
You get `ssl.SSLCertVerificationError` when making an HTTPS request. What is the secure resolution?
Answer: Update the CA certificates bundle used by Python or the requests library
Updating the CA bundle ensures Python can validate the server's certificate chain without disabling security.
A long-running script leaks memory over time. `tracemalloc` shows many small string allocations in a loop. What is a likely culprit?
Answer: String concatenation with `+` inside a loop, creating a new object each iteration
Each `+` on strings creates a new immutable string object; accumulation inside a loop grows memory linearly.
A subprocess call with `subprocess.run(['ls', '-l'])` works locally but raises `FileNotFoundError` on Windows. Why?
Answer: `ls` is a Unix command not available on Windows; use `dir` with `shell=True` on Windows
`ls` is a Unix shell command; Windows uses `dir`, and since it is a shell built-in, `shell=True` is required.
You add `print` statements to debug, but output is not visible when piping the script's stdout. What causes this?
Answer: Python buffers stdout when writing to a pipe; use flush=True or set PYTHONUNBUFFERED=1
Python uses block buffering for stdout when it detects a pipe, so output may not appear until the buffer is flushed.
A class method decorated with `@staticmethod` raises `TypeError: method() takes 0 positional arguments but 1 was given`. What went wrong?
Answer: The decorator was removed or misapplied, so Python is passing `self` to what should be a static method
Without `@staticmethod`, Python treats the method as an instance method and automatically passes `self` as the first argument.