[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #40612] NSTaskDidTerminateNotification posted late or never
From: |
Larry Campbell |
Subject: |
[bug #40612] NSTaskDidTerminateNotification posted late or never |
Date: |
Sun, 17 Nov 2013 21:12:23 +0000 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71 |
Follow-up Comment #2, bug #40612 (project gnustep):
The following test function works on Mac OS X, but fails with gnustep without
the fixes:
static BOOL taskTerminationNotificationReceived;
- (void)taskDidTerminate:(NSNotification *)notification
{
NSLog(@"Received NSTaskDidTerminateNotification %@", notification);
taskTerminationNotificationReceived = YES;
}
- (void)testNSTaskNotifications
{
NSDate *deadline;
BOOL earlyTermination = NO;
for (;;) {
NSTask *task = [NSTask new];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:[NSArray arrayWithObjects:@"-c", @"echo Child
starting; sleep 10; echo Child exiting", nil]];
taskTerminationNotificationReceived = NO;
[[NSNotificationCenter defaultCenter] addObserver: self
selector:
@selector(taskDidTerminate:)
name:
NSTaskDidTerminateNotification
object: task];
[task launch];
NSLog(@"Launched pid %d", [task processIdentifier]);
if (earlyTermination) {
NSLog(@"Running run loop for 5 seconds");
deadline = [NSDate dateWithTimeIntervalSinceNow:5.0];
while ([deadline timeIntervalSinceNow] > 0.0)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate
dateWithTimeIntervalSinceNow:1.0]];
NSLog(@"Run loop finished, will now call -[NSTask terminate]");
[task terminate];
NSLog(@"Terminate returned, waiting for termination");
[task waitUntilExit];
} else {
NSLog(@"Running run loop for 15 seconds");
deadline = [NSDate dateWithTimeIntervalSinceNow:15.0];
while ([deadline timeIntervalSinceNow] > 0.0 &&
!taskTerminationNotificationReceived)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate
dateWithTimeIntervalSinceNow:1.0]];
}
[task release];
NSAssert(taskTerminationNotificationReceived, @"termination
notification not received");
[[NSNotificationCenter defaultCenter] removeObserver:self
name:NSTaskDidTerminateNotification object:nil];
if (earlyTermination)
break;
earlyTermination = YES;
}
}
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?40612>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/