Finding Your Extra Python Processes#
The lessons learned in this page were part of the troubleshooting process for learning how to built this site.
Sometimes you may start a process that never ends, even when your IDE closes. Linux has a similar system, but in Windows you can see what processes are running and make informed decisions about which ones to stop.
The Problem: Identifying Running Python Processes#
When you have multiple Python processes running, you need to identify which ones are important (IDE tools) vs. which ones you want to stop (like a stuck development server).
Command 1: List All Python Processes#
Basic listing (shows only process names and IDs):
Output example:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
python.exe 27776 Console 1 45,632 K
python.exe 65964 Console 1 42,108 K
python.exe 52860 Console 1 38,944 K
python.exe 2416 Console 1 41,220 K
Problem: You can't tell which process is which! They all look the same.
Command 2: Show What Each Process Is Actually Running#
Advanced listing (shows full command line):
Output example:
CommandLine ProcessId
"c:\Program Files\Python\Python314\python.exe" c:\Users\gradu\.vscode\extensions\ms-python.black-formatter-2025.2.0\bundled\tool\lsp_server.py --stdio 27776
"c:\Program Files\Python\Python314\python.exe" c:\Users\gradu\.vscode\extensions\ms-python.flake8-2025.2.0\bundled\tool\lsp_server.py 65964
"c:\Program Files\Python\Python314\python.exe" c:\Users\gradu\.vscode\extensions\ms-python.pylint-2025.2.0\bundled\tool\lsp_server.py 52860
"c:\Program Files\Python\Python314\python.exe" c:\Users\gradu\.vscode\extensions\ms-python.mypy-type-checker-2025.2.0\bundled\tool\lsp_server.py 2416
Now you can identify each process:
- PID 27776: Black formatter (VS Code extension) ✅ Keep running
- PID 65964: Flake8 linter (VS Code extension) ✅ Keep running
- PID 52860: Pylint linter (VS Code extension) ✅ Keep running
- PID 2416: Mypy type checker (VS Code extension) ✅ Keep running
Command 3: Find Specific Processes#
Search for a specific program (like MkDocs):
This helps you find only the processes you're looking for, avoiding unnecessary noise.
Critical Thinking: When to Kill Processes#
❌ DON'T blindly kill all Python processes:
✅ DO investigate first, then selectively kill:
- Identify what each process is doing
- Decide which ones are safe to stop
- Kill selectively by PID:
Or better yet, stop it gracefully in the terminal where you started it (Ctrl+C).
Case Study: MkDocs Infinite Refresh Loop#
The Problem#
When running mkdocs serve with build hooks that modify watched files, you can get stuck in an infinite refresh loop:
- Hook runs during build → modifies a file in
docs/ - MkDocs sees the file change → triggers rebuild
- Hook runs again → modifies file again
- Loop repeats forever! 🔄
The Investigation#
Step 1: Recognize the symptom - Browser page constantly refreshes - Terminal shows continuous rebuild messages - Changes don't settle
Step 2: Check your configuration
Look at mkdocs.yml for hooks:
hooks:
- docs/hooks/priority_badges.py
- docs/hooks/generate_req_index.py # ⚠️ Generates files during build!
Root cause: The generate_req_index.py hook creates/modifies docs/requirements/req-index.md during every build, which triggers another build.
Step 3: Verify MkDocs is running
REM Search for MkDocs process
wmic process where "CommandLine like '%mkdocs%'" get CommandLine,ProcessId
If found, you know it's running and causing the loop.
The Solution#
Option 1: Stop auto-reload during development
- Prevents automatic page refresh
- Hooks still run on each manual build
- You manually refresh browser to see changes
Option 2: Dirty builds (skip unchanged files)
- Faster builds
- Only rebuilds changed files
- Best for rapid development
Option 3: Fix the hook (advanced)
Modify the hook to only write if content actually changed:
This prevents unnecessary file modifications that trigger rebuilds.
Lessons Learned#
- Investigate before acting - Don't kill all Python processes blindly
- Use detailed commands -
wmicwithCommandLineshows what's really running - Understand the system - Know how MkDocs watches files and triggers rebuilds
- Choose the right tool - Use
--no-livereloadwhen hooks modify watched files - Document solutions - Future you will thank present you! 📝
Command 4: Clean MkDocs Build Directory#
Purpose: Remove the site/ directory to force a fresh build and clear any cached content.
Command:
Breakdown:
if exist site- Check if thesitedirectory exists before trying to delete itrmdir- Remove directory command/s- Remove all subdirectories and files recursively (likerm -rfon Linux)/q- Quiet mode - don't prompt for confirmationsite- The directory name (MkDocs default build output)
When to use this:
- ✅ Status indicators not updating after config changes
- ✅ CSS/JavaScript changes not appearing on deployment
- ✅ Stale content showing up
- ✅ Before deploying to ensure clean build
- ✅ Troubleshooting rendering issues
Best practice:
REM Clean build directory, then rebuild
if exist site rmdir /s /q site && mkdocs build
REM But really it's the same as:
mkdocs build --clean
REM You should not do this because you cannot serve without site:
if exist site rmdir /s /q site && mkdocs serve
Quick Reference#
| Task | Command | Use Case |
|---|---|---|
| List Python processes | tasklist /FI "IMAGENAME eq python.exe" | See PIDs only |
| Show what's running | wmic process where "name='python.exe'" get CommandLine,ProcessId | Identify processes |
| Find specific program | wmic process where "CommandLine like '%mkdocs%'" get CommandLine,ProcessId | Target search |
| Kill by PID | taskkill /F /PID 12345 | Stop specific process |
| Clean build | if exist site rmdir /s /q site or mkdocs build --clean | Remove build cache |
| MkDocs no reload | mkdocs serve --no-livereload | Prevent refresh loop |
| MkDocs dirty build | mkdocs serve --dirty --no-livereload | Fast development |
Additional Resources#
- Windows Task Manager - Microsoft's guide to Task Manager
- WMIC Command Reference - Complete WMIC documentation
- MkDocs Serve Options - Official MkDocs CLI reference