Skip to content

Conversation

Copy link

Copilot AI commented Aug 4, 2025

This PR implements sanic-hmr, a new package that provides hot module reloading (HMR) capabilities for Sanic applications, following the same pattern as the existing uvicorn-hmr package.

What's Added

New Package: sanic-hmr

  • CLI wrapper that provides HMR functionality for Sanic applications
  • Reuses existing HMR infrastructure from the hmr library for consistency
  • ASGI-compatible backend using uvicorn to avoid Sanic's threading/signal handling limitations
  • Drop-in replacement for sanic app.py --auto-reload with much faster reload times

Key Features

  • 🚀 Hot module reloading - Only reloads changed modules and their dependencies
  • 🔧 Compatible CLI - Supports common Sanic server arguments (--host, --port, --debug, etc.)
  • Fast restarts - No full process restart, much faster than Sanic's built-in auto-reload
  • 🎯 Minimal changes - Works with existing Sanic applications with no code changes required

Usage

Replace this:

sanic app.py --auto-reload

With this:

sanic-hmr app:app

The server will now provide hot module reloading with significantly faster reload times compared to full process restarts.

Technical Implementation

  • Uses uvicorn as ASGI server backend to work around Sanic's signal handling restrictions in threads
  • Leverages the existing hmr library's file watching and module reloading capabilities
  • Implements the same architectural pattern as uvicorn-hmr for consistency
  • Includes factory pattern example in the Sanic demo app to handle HMR-friendly app creation

Example Application

Added a complete Sanic example in examples/sanic/ demonstrating:

  • Basic Sanic application structure
  • HMR-compatible app factory pattern
  • Multiple route types (text, JSON, parameterized)

This implementation provides Sanic developers with the same fast development experience that uvicorn-hmr provides for FastAPI/ASGI applications.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: CNSeniorious000 <74518716+CNSeniorious000@users.noreply.github.com>
Copilot AI changed the title [WIP] 仿照 uvicorn-hmr,实现一个 sanic-hmr,尽量复用原库的东西,做一个 wrapper 性质的 CLI Implement sanic-hmr: Hot Module Reloading wrapper CLI for Sanic Aug 4, 2025
Copilot AI requested a review from CNSeniorious000 August 4, 2025 22:34
@hyperlint-ai-deprecated
Copy link

PR Change Summary

Implemented the sanic-hmr package as a wrapper CLI for hot module reloading in Sanic, inspired by uvicorn-hmr.

  • Explored the repository structure and HMR pattern of uvicorn-hmr
  • Created the sanic-hmr package structure and main module
  • Added README documentation for sanic-hmr
  • Configured project settings to include sanic-hmr

Added Files

  • packages/sanic-hmr/README.md

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add hyperlint-ignore to the PR to ignore the link check for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants