Prechádzať zdrojové kódy

Merge pull request #547 from exo-explore/subprocessforkfix

subprocess fork fix
Alex Cheema 7 mesiacov pred
rodič
commit
d6d74e9c0e

+ 14 - 11
exo/helpers.py

@@ -8,9 +8,11 @@ import platform
 import psutil
 import uuid
 import netifaces
+import subprocess
 from pathlib import Path
 import tempfile
 import json
+from concurrent.futures import ThreadPoolExecutor
 
 DEBUG = int(os.getenv("DEBUG", default="0"))
 DEBUG_DISCOVERY = int(os.getenv("DEBUG_DISCOVERY", default="0"))
@@ -23,6 +25,9 @@ exo_text = r"""
  \___/_/\_\___/ 
     """
 
+# Single shared thread pool for subprocess operations
+subprocess_pool = ThreadPoolExecutor(max_workers=4, thread_name_prefix="subprocess_worker")
+
 
 def get_system_info():
   if psutil.MACOS:
@@ -239,10 +244,15 @@ def get_all_ip_addresses_and_interfaces():
 
 async def get_macos_interface_type(ifname: str) -> Optional[Tuple[int, str]]:
   try:
-    proc = await asyncio.create_subprocess_exec('system_profiler', 'SPNetworkDataType', '-json',
-      stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
-    output, _ = await proc.communicate()
-    data = json.loads(output.decode('utf-8'))
+    # Use the shared subprocess_pool
+    output = await asyncio.get_running_loop().run_in_executor(subprocess_pool, lambda: subprocess.run(
+      ['system_profiler', 'SPNetworkDataType', '-json'],
+      capture_output=True,
+      text=True,
+      close_fds=True
+    ).stdout)
+
+    data = json.loads(output)
 
     for interface in data.get('SPNetworkDataType', []):
       if interface.get('interface') == ifname:
@@ -250,21 +260,14 @@ async def get_macos_interface_type(ifname: str) -> Optional[Tuple[int, str]]:
         type_name = interface.get('type', '').lower()
         name = interface.get('_name', '').lower()
 
-        # Thunderbolt interfaces
         if 'thunderbolt' in name:
           return (5, "Thunderbolt")
-
-        # Ethernet adapters
         if hardware == 'ethernet' or type_name == 'ethernet':
           if 'usb' in name:
             return (4, "Ethernet [USB]")
           return (4, "Ethernet")
-
-        # WiFi/AirPort
         if hardware == 'airport' or type_name == 'airport' or 'wi-fi' in name:
           return (3, "WiFi")
-
-        # VPN interfaces
         if type_name == 'vpn':
           return (1, "External Virtual")
 

+ 1 - 1
exo/networking/udp/udp_discovery.py

@@ -42,7 +42,7 @@ class UDPDiscovery(Discovery):
     listen_port: int,
     broadcast_port: int,
     create_peer_handle: Callable[[str, str, str, DeviceCapabilities], PeerHandle],
-    broadcast_interval: int = 1,
+    broadcast_interval: int = 2.5,
     discovery_timeout: int = 30,
     device_capabilities: DeviceCapabilities = UNKNOWN_DEVICE_CAPABILITIES,
     allowed_node_ids: List[str] = None,

+ 1 - 1
exo/orchestration/standard_node.py

@@ -58,7 +58,7 @@ class StandardNode(Node):
     await self.update_peers(wait_for_peers)
     await self.collect_topology(set())
     if DEBUG >= 2: print(f"Collected topology: {self.topology}")
-    asyncio.create_task(self.periodic_topology_collection(1.0))
+    asyncio.create_task(self.periodic_topology_collection(2.0))
 
   async def stop(self) -> None:
     await self.discovery.stop()