From 464d258b0cc29f889fa3e36d43022a0c6ec8a546 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 11 Oct 2020 00:38:29 +0200 Subject: Server: Ensure the process is terminated before starting a new one Just in case. Was getting a runtime exception occasionally and am still not entirely sure why. It happened in the `[Server stop]` call. Also check if the process is running before terminating it. Didn't read about whether we're required to do this, but it seemed logical. --- Drop Serve/Server.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Drop Serve/Server.m b/Drop Serve/Server.m index 21da986..ad6146b 100644 --- a/Drop Serve/Server.m +++ b/Drop Serve/Server.m @@ -12,6 +12,8 @@ + (void)serveAtPath:(NSString *)path { + [self stop]; + _process = [[NSTask alloc] init]; [_process setCurrentDirectoryPath:path]; [_process setLaunchPath:@"/usr/bin/python"]; @@ -27,7 +29,10 @@ + (void)stop { - [_process terminate]; + if ([_process isRunning]) { + [_process terminate]; + } + [_process dealloc]; } -- cgit v1.2.3