Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Support for listening on random port and opening browser without delays

Đang mở
#214 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Start by reviewing the server startup path in livereload.server and the web.Application and Server references shown in the issue. Use the monkeypatch example to understand the requested random-port and browser-opening behavior. Done means the server supports these flows without delays and exposes enough startup hooks for subclassing or customization.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

type: feature

Hello,

I wanted to support opening a browser on a random local port, and got it working with a bit of monkeypatching:

        server = make_server(…)
                
        import tornado.web
        import tornado.httpserver
        import tornado.netutil                   
        import webbrowser
                    
        class Application(tornado.web.Application):
            def listen(self, *args, **kw):
                sockets = tornado.netutil.bind_sockets(0, 'localhost')
                server = tornado.httpserver.HTTPServer(self)
                server.add_sockets(sockets)
                pairs = []
                for s in sockets:        
                    pairs.append(s.getsockname()[:2])
                pairs.sort()
                host, port = pairs[0]
                if ":" in host:    
                    host = f"[{host}]"    
                url = f"http://{host}:{port}"    
                log.info("Listening on %s", url)    
        
                async def open_browser():        
                    webbrowser.open_new_tab(url)     
 
                tornado.ioloop.IOLoop.current().add_callback(open_browser)    
                return server

        # Monkey patch to be able to start servers in a smoother way that the
        # defaults of livereload
        import livereload.server
        livereload.server.web.Application = Application
        server.serve()

Integrating this in livereload seems to require some refactoring of how the server is started, and I didn't engage on it. I hope that my monkeypatched code can be a useful reference.

Ideally, I would have liked to be able to subclass Server or the Application used by server, and have enough hooks to intervene in the listening bit.

Ngôn ngữ chính
Python
Star
1.1k
Fork
149
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lepture/python-livereload

Tất cả issue của lepture/python-livereload

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.