惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
Recent Announcements
Recent Announcements
D
DataBreaches.Net
P
Proofpoint News Feed
V
Visual Studio Blog
J
Java Code Geeks
Recorded Future
Recorded Future
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Full Disclosure
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
罗磊的独立博客
Jina AI
Jina AI
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
G
GRAHAM CLULEY
Y
Y Combinator Blog
L
LangChain Blog
L
LINUX DO - 热门话题
宝玉的分享
宝玉的分享
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security
云风的 BLOG
云风的 BLOG
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园_首页
A
About on SuperTechFans
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Latest news
Latest news
T
Threatpost
T
Tenable Blog
有赞技术团队
有赞技术团队
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Stack Overflow Blog
Stack Overflow Blog
C
Cisco Blogs
C
Check Point Blog
T
Tor Project blog
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
美团技术团队
I
Intezer
S
Securelist
AWS News Blog
AWS News Blog

Stonecharioteer on Tech

I Traced My Traffic Through a Home Tailscale Exit Node What Was I Reading Last? In Three Not-So-Easy Pieces Dogfooding Is Hard Code blocks in your books, finally GoForGo v0.9.0 Merrilin - We built an app to read books I use a Macbook now Data Structures & Algorithms - Preparing for Interviews Using a local DNS namespace for local service discovery Direction KOllector - Publishing KOReader Highlights gbt: branches touched in the last 24 hours A Soiree into Symbols in Ruby Some Smalltalk about Ruby Loops Ruby Blocks Returning from Ruby Blocks, Procs and Lambdas My Linux Laptop Finally Works: How Claude Helped Me Fix Years of Annoyances TIL: Watchexec - Modern File Watching for Development Workflows A Less Busy Mind GoForGo - Learn Go through live examples Migrating My Old Blog to Hugo with Claude The Qtile Window Manager: A Python-Powered Tiling Experience Read the RFCs that Built the Internet Py-x-Protobuf - Or How I Learned to Stop Worrying and Love Protocol Buffers Python Reverse a List New Beginnings Leaving ChainSafe Systems Screen Lock for Cinnamon Desktop using Zenity and Terminal Commands Crews Not Teams A System for Getting Better at LeetCode So Far So Rust Retrying HTTP Requests with Rust A Primer on Control Charts Learning Rust Explicit is Better than Implicit: Rust for Pythonistas Using Custom Delimiters in Jinja Templates TIL: Creating Fixed Length Iterables in Python Documentation Without Assumption Vagrant Python - A Reflection in 2022 Learning Golang No, A Virtual Machine Is Not Enough: Why Developers Need Native Linux Empathy in Tech For Those Who Came in Late A Weekend With PostgreSQL TIL: Gooey and Python Fire for Quick GUIs and CLIs TIL: 2ality - Dr. Axel Rauschmayer's JavaScript Blog TIL: MassDNS - High-Performance Bulk DNS Lookups TIL: Matomo Analytics, Google Tech Writing, Memory Programming, and NES TV Signals TIL: MontyDB - MongoDB Implemented in Python Returning to the Craft of Programming TIL: CPUFetch, OneFetch, and Learn CSS TIL: DNS Performance Testing and Pi-hole with Unbound TIL: Eli Bendersky's Blog, Awesome By Example, NoCoDB, and Martin Kleppmann TIL: CRDTs, Extreme HTTP Performance, and BYTEPATH Game TIL: AutoInvent, ASGI, Python Packaging, RAPIDS GPU Computing, and FlaskCon TIL: MangaDesk - Terminal Client for MangaDex TIL: McFly - Smart Shell History Search TIL: Siege Load Testing and Awesome FastAPI Resources TIL: Ventoy Bootable USB and Justniffer Network Analysis TIL: CLI Code Review, Git Split Diffs, and Internal Combustion Engine TIL: Benford's Law, Web Security Headers, Event Sourcing, and Mozilla Security Guidelines How to Write Documentation - The README.md File The Importance of Documentation TIL: NNgroup UX Research, SponsorBlock, and Labella Python Library TIL: The Little Book of Rust Macros and Rust Performance Book TIL: Git-Bug Distributed Issue Tracker and Omni Kubernetes Monitoring TIL: Zellij - Modern Terminal Multiplexer TIL: How Discord Handles 2.5 Million Concurrent Voice Users TIL: Volumio - The Audiophile Music Player TIL: Areopagitica - Milton's Defense of Free Speech TIL: Fast Node Manager, Zoxide Smart CD, Technical Writing, PyO3, and Qubes OS TIL: Slurm Workload Manager for HPC Clusters TIL: Data Visualization Guide and Oso Authorization Academy TIL: CORS Deep Dive, Piku Tiny PaaS, Rust Strings, and Deno Standard Library TIL: Raspberry Pi OS Development, Vim Beginner Guide, Password Management, and QueryBook TIL: uBlock Origin Performance Optimization on Firefox TIL: Breaking PostgreSQL at Scale and LeetCode Problem Patterns TIL: Awesome Tmux Resources for Terminal Multiplexing TIL: Grit - A Multitree-Based Personal Task Manager TIL: Lens 4.2 Kubernetes IDE, Shell Scripting Guide, and Dark HTTP Server Do The Job You Hate So You Won't Hate The Job You Love TIL: Innernet VPN Solution and NoteCalc Calculator App TIL: Argo CD for GitOps and Lens Kubernetes IDE TIL: Modern Rust CLI Tools - System Monitoring, HTTP Requests, and DNS TIL: tz - A Time Zone Helper Tool TIL: Distributed Systems Education, Fallacies, and Self-Hosted Internet Archiving TIL: Real-Time Voice Cloning Technology TIL: ChartMuseum for Helm, AMD's Corporate Journey, and Kubernetes Pod Scaling TIL: Docker and Kubernetes Tools - Whaler, Descheduler, and Dive TIL: Post-Mortem Collection, Terminal Plotting, and Technical Twitter TIL: Dark Mode Toggle Web Component by Google Chrome Labs TIL: Python eval(), exec(), and compile() Functions TIL: Camelot PDF Tables, PostgreSQL Row Level Security, Zerodha Varsity, and Write Yourself a Git TIL: fuser Command for Process and File Investigation TIL: i Hate Regex - The Ultimate Regex Cheat Sheet TIL: Dolt - Git for Data and Database Version Control TIL: x86 Assembly Programming and SafeEyes Break Reminder TIL: Comprehensive Distributed Systems Reading List TIL: Cosmopolitan C Library, Distributed Systems Book, High Performance Browser Networking, and Rust Roguelike Tutorial
TIL: Python's raise from Statement, Grub Customization, Liquorix Kernel, and Hardware Benchmarking
2020-08-05 · via Stonecharioteer on Tech

Today’s discoveries spanned from Python exception handling best practices to Linux system customization and performance optimization.

Python’s raise statement with from clause enables proper exception chaining to preserve full tracebacks:

Exception Chaining Fundamentals:

Basic raise from Usage:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
def process_file(filename):
    try:
        with open(filename, 'r') as f:
            data = json.load(f)
            return data['required_field']
    except FileNotFoundError as e:
        raise ValueError(f"Configuration file {filename} not found") from e
    except KeyError as e:
        raise ValueError(f"Missing required field in {filename}") from e
    except json.JSONDecodeError as e:
        raise ValueError(f"Invalid JSON in {filename}") from e

# Usage example
try:
    config = process_file('config.json')
except ValueError as e:
    print(f"Error: {e}")
    print(f"Original cause: {e.__cause__}")
    print(f"Full traceback includes both exceptions")

Suppressing Exception Context:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def clean_error_without_context():
    try:
        risky_operation()
    except InternalError:
        # Suppress the original exception from traceback
        raise UserFriendlyError("Operation failed") from None

def clean_error_with_context():
    try:
        risky_operation()
    except InternalError as e:
        # Preserve original exception for debugging
        raise UserFriendlyError("Operation failed") from e

Advanced Exception Chaining Patterns:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import logging
from contextlib import contextmanager

class DatabaseError(Exception):
    """Custom exception with enhanced context"""
    def __init__(self, message, query=None, params=None):
        super().__init__(message)
        self.query = query
        self.params = params

@contextmanager
def database_transaction():
    """Context manager with proper exception handling"""
    connection = None
    try:
        connection = get_database_connection()
        connection.begin()
        yield connection
        connection.commit()
    except DatabaseConnectionError as e:
        if connection:
            connection.rollback()
        raise DatabaseError("Transaction failed - connection issue") from e
    except DatabaseQueryError as e:
        if connection:
            connection.rollback()
        raise DatabaseError(
            "Transaction failed - query error",
            query=e.query,
            params=e.params
        ) from e
    finally:
        if connection:
            connection.close()

# Usage with comprehensive error handling
def update_user_profile(user_id, profile_data):
    try:
        with database_transaction() as db:
            # Multiple operations that might fail
            user = db.get_user(user_id)
            if not user:
                raise UserNotFoundError(f"User {user_id} not found")

            validate_profile_data(profile_data)
            db.update_user_profile(user_id, profile_data)
            db.log_user_activity(user_id, "profile_updated")

    except UserNotFoundError:
        # Re-raise without chaining - this is the root cause
        raise
    except ValidationError as e:
        raise ProfileUpdateError("Invalid profile data") from e
    except DatabaseError as e:
        logging.error(f"Database error updating user {user_id}: {e.__cause__}")
        raise ProfileUpdateError("Failed to update profile") from e

Exception Chaining Best Practices:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def api_request_with_retries(url, max_retries=3):
    """Example showing when to chain vs when not to chain"""
    last_exception = None

    for attempt in range(max_retries):
        try:
            response = requests.get(url, timeout=10)
            response.raise_for_status()
            return response.json()

        except requests.ConnectionError as e:
            last_exception = e
            if attempt == max_retries - 1:
                # Chain the last connection error
                raise APIConnectionError(
                    f"Failed to connect to {url} after {max_retries} attempts"
                ) from e
            time.sleep(2 ** attempt)  # Exponential backoff

        except requests.HTTPError as e:
            # Don't retry on HTTP errors - raise immediately with context
            raise APIHttpError(
                f"HTTP {e.response.status_code}: {e.response.reason}"
            ) from e

        except requests.Timeout as e:
            last_exception = e
            if attempt == max_retries - 1:
                raise APITimeoutError(
                    f"Request to {url} timed out after {max_retries} attempts"
                ) from e
            time.sleep(1)

Grub Bootloader Customization

Grub Customizer provides a GUI tool for customizing the GRUB bootloader:

Grub Configuration Methods:

Manual Configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Edit GRUB configuration
sudo nano /etc/default/grub

# Common customizations
GRUB_DEFAULT=0                    # Default menu entry
GRUB_TIMEOUT=10                   # Menu timeout in seconds
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"  # Kernel parameters
GRUB_CMDLINE_LINUX=""
GRUB_GFXMODE=1920x1080           # Screen resolution
GRUB_BACKGROUND="/path/to/image.jpg"  # Custom background

# Apply changes
sudo update-grub

Advanced Grub Customization:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Custom menu entries
sudo nano /etc/grub.d/40_custom

# Add custom entry
menuentry "Ubuntu Safe Mode" {
    set root='hd0,gpt2'
    linux /vmlinuz root=/dev/sda2 ro recovery nomodeset
    initrd /initrd.img
}

menuentry "Memory Test" {
    set root='hd0,gpt1'
    linux16 /memtest86+.bin
}

# Custom theme installation
sudo mkdir -p /boot/grub/themes/mytheme
sudo cp -r mytheme/* /boot/grub/themes/mytheme/

# Enable theme in /etc/default/grub
GRUB_THEME="/boot/grub/themes/mytheme/theme.txt"

Grub Rescue Operations:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Boot repair from live USB
sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt update
sudo apt install boot-repair
sudo boot-repair

# Manual GRUB reinstallation
sudo mount /dev/sda2 /mnt  # Root partition
sudo mount /dev/sda1 /mnt/boot/efi  # EFI partition
sudo grub-install --target=x86_64-efi --efi-directory=/mnt/boot/efi --bootloader-id=ubuntu /dev/sda
sudo update-grub

Liquorix Kernel for Desktop Performance

Liquorix Kernel provides optimized kernel builds for desktop and multimedia workloads:

Liquorix Features:

Performance Optimizations:

  • MuQSS Scheduler: Better interactive performance than CFS
  • Low latency: Optimized for real-time audio/video work
  • Desktop responsiveness: Reduced input lag and smoother UI
  • Gaming optimizations: Better frame time consistency

Installation:

1
2
3
4
5
6
7
8
9
# Add Liquorix repository
curl -s 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x9ae4078033f8024d' | sudo apt-key add -
echo "deb http://liquorix.net/debian sid main" | sudo tee /etc/apt/sources.list.d/liquorix.list

# Install Liquorix kernel
sudo apt update
sudo apt install linux-image-liquorix-amd64 linux-headers-liquorix-amd64

# Reboot and select Liquorix kernel from GRUB menu

Kernel Comparison:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Check current kernel
uname -r

# Compare different kernels
# Standard Ubuntu kernel: 5.4.0-generic
# Liquorix kernel: 5.4-liquorix-amd64
# XanMod kernel: 5.4.0-xanmod1

# Performance testing
# Audio latency test
sudo apt install rt-tests
cyclictest -t1 -p 80 -n -i 500 -l 100000

# System responsiveness
time (dd if=/dev/zero of=/tmp/test bs=1M count=1000; sync)

Phoronix Test Suite - Hardware Benchmarking

Phoronix Test Suite provides comprehensive open-source benchmarking tools:

Benchmarking Capabilities:

Installation and Basic Usage:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Install Phoronix Test Suite
sudo apt install phoronix-test-suite

# List available tests
phoronix-test-suite list-available-tests

# System information
phoronix-test-suite system-info

# Hardware detection
phoronix-test-suite detailed-system-info

CPU Benchmarking:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# CPU-intensive benchmarks
phoronix-test-suite install pts/compress-7zip
phoronix-test-suite run pts/compress-7zip

# Multi-threaded compilation test
phoronix-test-suite install pts/build-linux-kernel
phoronix-test-suite run pts/build-linux-kernel

# Encryption performance
phoronix-test-suite install pts/openssl
phoronix-test-suite run pts/openssl

GPU and Graphics Benchmarking:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# OpenGL performance
phoronix-test-suite install pts/unigine-valley
phoronix-test-suite run pts/unigine-valley

# Vulkan benchmarks
phoronix-test-suite install pts/vkmark
phoronix-test-suite run pts/vkmark

# GPU compute
phoronix-test-suite install pts/luxcorerender
phoronix-test-suite run pts/luxcorerender

Automated Test Suites:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Comprehensive system test
phoronix-test-suite install pts/desktop
phoronix-test-suite run pts/desktop

# Server benchmarks
phoronix-test-suite install pts/server
phoronix-test-suite run pts/server

# Custom test suite
phoronix-test-suite build-suite

# Batch testing with results upload
phoronix-test-suite batch-setup
phoronix-test-suite batch-run pts/desktop
phoronix-test-suite upload-result

Results Analysis:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# View test results
phoronix-test-suite list-saved-results
phoronix-test-suite show-result [result-name]

# Compare results
phoronix-test-suite merge-results result1 result2
phoronix-test-suite compare-results-to-baseline result1 baseline

# Generate reports
phoronix-test-suite result-file-to-pdf result1
phoronix-test-suite result-file-to-csv result1

Multiple Kernel Testing:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Automated kernel comparison script
#!/bin/bash
KERNELS=("5.4.0-generic" "5.4-liquorix" "5.4.0-xanmod1")
TESTS=("pts/compress-7zip" "pts/openssl" "pts/build-linux-kernel")

for kernel in "${KERNELS[@]}"; do
    echo "Testing kernel: $kernel"
    # Boot into specific kernel (manual step)
    # Then run benchmarks
    for test in "${TESTS[@]}"; do
        phoronix-test-suite run $test
        mv ~/.phoronix-test-suite/test-results/* "./results-$kernel-$(basename $test)/"
    done
done

# Generate comparison report
phoronix-test-suite merge-results results-*

These tools and techniques provide comprehensive approaches to Python error handling, Linux system customization, and performance analysis - essential skills for effective software development and system administration.