diff --git a/CHANGELOG.md b/CHANGELOG.md index 293d1b7e36..092d7b380b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ No changes to highlight. - Fixes type in client `Status` enum by [@10zinten](https://github.com/10zinten) in [PR 3931](https://github.com/gradio-app/gradio/pull/3931) - Fix `gr.ChatBot` to handle image url [tye-singwa](https://github.com/tye-signwa) in [PR 3953](https://github.com/gradio-app/gradio/pull/3953) - Move Google Tag Manager related initialization code to analytics-enabled block by [@akx](https://github.com/akx) in [PR 3956](https://github.com/gradio-app/gradio/pull/3956) +- Fix bug where port was not reused if the demo was closed and then re-launched by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3896](https://github.com/gradio-app/gradio/pull/3959) ## Documentation Changes: diff --git a/gradio/networking.py b/gradio/networking.py index 7bc66dd9a9..0e8e5fb48b 100644 --- a/gradio/networking.py +++ b/gradio/networking.py @@ -116,6 +116,7 @@ def start_server( else: try: s = socket.socket() + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((LOCALHOST_NAME, server_port)) s.close() except OSError: diff --git a/test/test_blocks.py b/test/test_blocks.py index 2f2b7577a4..0f9a833a53 100644 --- a/test/test_blocks.py +++ b/test/test_blocks.py @@ -263,6 +263,16 @@ class TestBlocksMethods: completed = True assert msg["output"]["data"][0] == "Victor" + def test_socket_reuse(self): + + try: + io = gr.Interface(lambda x: x, gr.Textbox(), gr.Textbox()) + io.launch(server_port=9441, prevent_thread_lock=True) + io.close() + io.launch(server_port=9441, prevent_thread_lock=True) + finally: + io.close() + def test_function_types_documented_in_config(self): def continuous_fn(): return 42