Răsfoiți Sursa

fix hanging reload when httpx range-requests are still open

Rodja Trappe 1 an în urmă
părinte
comite
39bfd667fd
1 a modificat fișierele cu 4 adăugiri și 0 ștergeri
  1. 4 0
      nicegui/air.py

+ 4 - 0
nicegui/air.py

@@ -2,6 +2,7 @@ import asyncio
 import gzip
 import gzip
 import json
 import json
 import re
 import re
+import signal
 from dataclasses import dataclass
 from dataclasses import dataclass
 from typing import Any, AsyncIterator, Dict, Optional
 from typing import Any, AsyncIterator, Dict, Optional
 from uuid import uuid4
 from uuid import uuid4
@@ -161,6 +162,9 @@ class Air:
 
 
     async def connect(self) -> None:
     async def connect(self) -> None:
         """Connect to the NiceGUI On Air server."""
         """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:
         if self.connecting:
             return
             return
         self.connecting = True
         self.connecting = True