NSURLSessionDataTask *dataTask = [self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error)
{
NSLog(@"Did fail with error %@" , [error localizedDescription]);
fail();
return ;
}
else
{
}
I use dataTaskWithRequest
to send async http request and in the completion block, i want to run a python script
.
NSTask * task = [[NSTask alloc] init];
[task setLaunchPath:kPythonPath];
[task setArguments:@[self.scriptFileFullPath,outputFile]];
[task launch];
[task waitUntilExit];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkPythonTaskStatus:) name:NSTaskDidTerminateNotification object:task];
the python
task may take a long time so i should wait for its completion. But the NSTaskDidTerminateNotification
will not be sent since the NSTask
is running in a separate thread. Anyone know how to wait for NSTask
to finish in this condition?