Recent writings

Signal handling in a multithreaded socket server

Gracefully shutdown Python's ThreadingTCPServer with signal handlers for SIGINT, SIGTERM handling and client notification on server shutdown.

Switching between multiple data streams in a single thread

Poll multiple data sources in a single thread using Python generators with itertools.cycle to alternate between infinite data streams efficiently.

Skipping the first part of an iterable in Python

Skip elements in iterables until a condition is met using itertools.dropwhile for efficient lazy evaluation that works with generators.

Pausing and resuming a socket server in Python

Build a pausable socket server with Python's socketserver module using threading for intermittent request handling and background tasks.

Debugging a containerized Django application in Jupyter Notebook

Connect Jupyter Notebook to Dockerized Django apps using ipykernel and django-extensions for interactive debugging and data exploration.

Manipulating text with query expressions in Django

Use Django query expressions like Replace, Upper, Lower, Concat, and Substr for efficient database-level text manipulation without fetching data.

Using tqdm with concurrent.fututes in Python

Display progress bars for concurrent Python tasks using tqdm with ThreadPoolExecutor and as_completed for real-time execution monitoring.

Colon command in shell scripts

Use the colon : command as a no-op in Bash scripts for cleaner debug output with -x flag. Alternative to echo for section markers and comments.

Faster bulk_update in Django

Accelerate Django bulk_update operations by 4x using multiprocessing to parallelize database writes across chunked record batches.

Installing Python on macOS with asdf

Manage multiple Python versions on macOS using asdf, a unified version manager replacing pyenv, nvm, and language-specific tools.

Save models with update_fields for better performance in Django

Optimize Django model saves with update_fields parameter to generate leaner SQL queries and improve performance in tight update loops.

Python logging quirks in AWS Lambda environment

Configure Python logging for AWS Lambda's pre-configured handlers while maintaining compatibility with local development environments.

Dissecting an outage caused by eager-loading file content

Learn from a production outage caused by loading large CSV files into memory. Stream process files to prevent OOM errors and crashes.

Auditing commit messages on GitHub

Automate commit message validation with GitHub Actions. Enforce refs and closes patterns to maintain clean Git history and link commits to issues.

To quote or not to quote

Master shell quoting rules: single vs double quotes, backticks vs $(). Learn when to quote variables to prevent spaces and special characters from breaking commands.