Why my 4GB Raspberry Pi 4 keeps swapping during a Python script – and how I fixed it by moving swap to USB

Why the Pi keeps swapping

I was running a memory‑hungry Python data‑pipeline on a 4 GB Raspberry Pi 4 when the system started thrashing every few minutes. top was showing swap usage climbing to 90 % while my script was still busy. The Pi’s 4 GB RAM was the hard limit, and the default swap file on the SD card was the culprit.

The culprit

The SD card is the only storage medium on the Pi, but it’s also the slowest. When the kernel starts paging, it writes to the swap file on the card, creating I/O bottlenecks that stall the Python interpreter. The swap file is defined in /etc/fstab:

[Read More]

Gunicorn - A Powerful Python WSGI Application Server

Understanding Gunicorn, Its Features, and How to Use It

When deploying a Python web application, you need a robust and efficient application server to handle incoming requests. One of the most popular choices is Gunicorn (Green Unicorn), a Python WSGI application server known for its simplicity, speed, and reliability.

Gunicorn is widely used in production environments to serve Django, Flask, and other WSGI applications. It acts as a middleware between a web server (like Nginx or Apache) and your Python application, efficiently managing multiple worker processes to handle concurrent requests.

[Read More]

uWSGI - A High-Performance Application Server

Understanding uWSGI, Its Features, and How to Use It

Introduction

When deploying Python web applications in production, having a reliable and efficient application server is crucial. One of the most powerful and flexible solutions available is uWSGI—a robust WSGI application server that supports Python and many other languages.

uWSGI is known for its high performance, extensive feature set, and flexibility. It can be used to serve Flask, Django, and other WSGI applications while integrating seamlessly with web servers like Nginx and Apache.

[Read More]