Skip to content

Conversation

Copy link

Copilot AI commented Aug 5, 2025

This PR adds a comprehensive Sanic example to demonstrate HMR (Hot Module Reload) functionality with the Sanic async web framework.

What's Added

  • Complete Sanic example in examples/sanic/ following the same structure as existing FastAPI and Flask examples
  • Blueprint-based architecture with modular components (a.py, b.py) to showcase HMR capabilities
  • Custom server integration using multiprocessing to handle Sanic's signal requirements
  • JSON API endpoints demonstrating proper Sanic response handling

Key Features

HMR Integration

The example uses a multiprocessing-based approach to run Sanic servers, avoiding signal handling conflicts that occur when running Sanic in threads. This allows HMR to work seamlessly:

# Changes to blueprint modules are hot-reloaded instantly
@b.route("/")
async def index(request):
    return json({"message": "This updates without server restart!"})

Efficient Reloading

Like other examples, it demonstrates HMR's efficiency by including a slow import simulation in a.py that only runs once, even during hot reloads.

Dynamic App Naming

Implements dynamic Sanic app naming to prevent registry conflicts during reloads:

app_name = f"SanicExample_{int(time.time())}"
app = Sanic(app_name)

Usage

cd examples/sanic
hmr app.py

Then visit:

  • http://localhost:8000/ - Main app info
  • http://localhost:8000/a - Blueprint A
  • http://localhost:8000/b - Blueprint B (try modifying this file to see HMR in action)
  • http://localhost:8000/b/test - Test endpoint

Testing Verified

  • ✅ Server starts successfully with HMR enabled
  • ✅ All endpoints respond with proper JSON
  • ✅ Hot reloading works - file changes are reflected immediately
  • ✅ Slow imports are not re-executed during reloads (demonstrating HMR efficiency)
  • ✅ Server lifecycle management works correctly

This completes the web framework examples trilogy, providing developers with HMR integration patterns for FastAPI, Flask, and now Sanic.


💬 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>
@hyperlint-ai-deprecated
Copy link

PR Change Summary

Implemented a complete Sanic example demonstrating Hot Module Reload (HMR) functionality.

  • Created a new Sanic example with HMR support
  • Developed main app and blueprint modules to showcase modular structure
  • Integrated multiprocessing for HMR to avoid signal handling issues
  • Added README with usage instructions and available endpoints

Added Files

  • examples/sanic/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.

1 similar comment
@hyperlint-ai-deprecated
Copy link

PR Change Summary

Implemented a complete Sanic example demonstrating Hot Module Reload (HMR) functionality.

  • Created a new Sanic example with HMR support
  • Developed main app and blueprint modules to showcase modular structure
  • Integrated multiprocessing for HMR to avoid signal handling issues
  • Added README with usage instructions and available endpoints

Added Files

  • examples/sanic/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.

Copilot AI changed the title [WIP] 新增一个 sanic 的 example 新增 Sanic 示例 (Add Sanic Example) Aug 5, 2025
Copilot AI requested a review from CNSeniorious000 August 5, 2025 04:11
@CNSeniorious000 CNSeniorious000 changed the title 新增 Sanic 示例 (Add Sanic Example) Add Sanic Example Sep 11, 2025
@CNSeniorious000 CNSeniorious000 force-pushed the readme branch 3 times, most recently from b044a10 to 59e0c95 Compare December 29, 2025 05:50
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