Skip to content

Conversation

maboloshi
Copy link

This PR adds a stop() method to the livereload.Server class, enabling proactive and graceful shutdown of the development server—particularly important for threaded integrations such as Sublime Text plugins or testing environments.

✨ Key Changes:

  • Server.stop():

    • Closes all registered HTTP server instances (created via .listen())
    • Checks if the underlying Tornado IOLoop (which wraps asyncio) is still running via self.ioloop.asyncio_loop.is_running()
    • Uses self.ioloop.add_callback(self.ioloop.stop) to safely stop the loop from any thread
  • Thread-safe and robust: Designed to work reliably even when livereload is used in non-main threads

  • No breaking changes: This is an additive change; existing behavior remains untouched unless .stop() is explicitly called

✅ Benefits:

  • Enables Sublime Text plugins (or other threaded environments) to cleanly terminate livereload without lingering ports or resources
  • Prevents issues like OSError: address already in use when restarting livereload
  • Opens up the ability to build testable and restartable development tools on top of livereload

- Added a stop() method to livereload.Server to allow proactive shutdown
- Closes all listening HTTP servers and releases bound ports
- Uses asyncio_loop.is_running() to check IOLoop state safely
- Stops IOLoop via add_callback() to ensure thread-safe termination
- Enables better integration with threaded environments
maboloshi added a commit to maboloshi/LiveReloadPy that referenced this pull request Jul 10, 2025
• 对 livereload 上游项目添加停止功能补丁 (PR lepture/python-livereload#284)
• 在插件中直接调用 server.stop() 方法停止服务
• 移除插件中复杂的 IOLoop 直接操作
• 优化资源清理流程
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.

1 participant