Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supporting auto reload on config change #382

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions exo/networking/manual/manual_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@
from exo.networking.manual.network_topology_config import NetworkTopology, PeerConfig
from exo.helpers import DEBUG_DISCOVERY
from exo.networking.peer_handle import PeerHandle
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class ConfigReloadEvent(FileSystemEventHandler):
def __init__(self, discovery: "ManualDiscovery"):
self.discovery = discovery

def on_changed(self, event):
if event.src_path == self.discovery.network_config_path:
if DEBUG_DISCOVERY >= 1: print(f"configuration file {self.discovery.network_config_path} has changed. updating topology...")
next_topology = NetworkTopology.from_path(self.discovery.network_config_path)
self.discovery.topology = next_topology
self.discovery.peers_in_network = next_topology.peers
self.discovery.peers_in_network.pop(self.discovery.node_id)

class ManualDiscovery(Discovery):
def __init__(
Expand All @@ -29,10 +42,21 @@ def __init__(

async def start(self) -> None:
self.listen_task = asyncio.create_task(self.task_find_peers_from_config())
self.start_watching_config_file()

async def stop(self) -> None:
if self.listen_task:
self.listen_task.cancel()
self.stop_watching_config_file()

def start_watching_config_file(self):
event_handler = ConfigReloadEvent(self)
self.config_observer = Observer()
self.config_observer.schedule(event_handler, self.network_config_path, recursive=False)

def stop_watching_config_file(self):
if hasattr(self, "config_observer"):
self.config_observer.stop()

async def discover_peers(self, wait_for_peers: int = 0) -> List[PeerHandle]:
if wait_for_peers > 0:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"tenacity==9.0.0",
"tqdm==4.66.4",
"transformers==4.43.3",
"watchdog==5.0.3",
"uuid==1.30",
"tinygrad @ git+https://github.com/tinygrad/tinygrad.git@232edcfd4f8b388807c64fb1817a7668ce27cbad",
]
Expand Down