Skip to content

Commit 7104f0b

Browse files
committed
fix: Wait for daemon to come online via busy loop
1 parent 403da92 commit 7104f0b

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/main/java/io/github/berstanio/pymobiledevice3/daemon/DaemonHandler.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,17 @@ public static void startDaemon(PyInstallation installation) throws IOException {
9797
pb.redirectOutput(getLogFile());
9898
pb.start();
9999

100-
try (WatchService watchService = FileSystems.getDefault().newWatchService()){
101-
portFile.toPath().getParent().register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
102-
while (true) {
103-
WatchKey key = watchService.take();
104-
for (WatchEvent<?> event : key.pollEvents()) {
105-
WatchEvent.Kind<?> kind = event.kind();
106-
if (kind != StandardWatchEventKinds.ENTRY_MODIFY)
107-
continue;
108-
Path modifiedFile = (Path) event.context();
109-
if (!modifiedFile.toString().equals(portFile.getName()))
110-
continue;
111-
if (getDaemonPort() != -1)
112-
return;
113-
}
100+
for (int i = 0; i < 60; i++) {
101+
if (isDaemonRunning()) {
102+
return;
103+
}
104+
try {
105+
Thread.sleep(1000);
106+
} catch (InterruptedException e) {
107+
throw new RuntimeException(e);
114108
}
115-
} catch (InterruptedException e) {
116-
throw new RuntimeException(e);
117109
}
110+
throw new RuntimeException("Failed to start Daemon - timeout");
118111
}
119112

120113
private static String getUnixUserId() {

0 commit comments

Comments
 (0)