浏览代码

fix hanging reload when httpx range-requests are still open

Rodja Trappe 1 年之前
父节点
当前提交
39bfd667fd
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4 0
      nicegui/air.py

+ 4 - 0
nicegui/air.py

@@ -2,6 +2,7 @@ import asyncio
 import gzip
 import json
 import re
+import signal
 from dataclasses import dataclass
 from typing import Any, AsyncIterator, Dict, Optional
 from uuid import uuid4
@@ -161,6 +162,9 @@ class Air:
 
     async def connect(self) -> None:
         """Connect to the NiceGUI On Air server."""
+        # ensure that the connection is closed when the process is terminated
+        signal.signal(signal.SIGINT, disconnect)
+        signal.signal(signal.SIGTERM, disconnect)
         if self.connecting:
             return
         self.connecting = True