Re: Can't obtain any more NSPipe instances
Re: Can't obtain any more NSPipe instances
- Subject: Re: Can't obtain any more NSPipe instances
- From: Glenn Zelniker <email@hidden>
- Date: Sun, 28 May 2006 22:10:04 -0400
On May 28, 2006, at 9:55 PM, Alexander Reichstadt wrote:
Hi,
There is some odd behaviour with NSPipe I can't figure out, or
maybe it's with my code. The following demonstrates the problem;
when running the following code it always fails at iteration 246:
- (IBAction)test:(id)sender
{
int i;
for (i=0;i<1000;i++){
NSTask *task = [[NSTask alloc] init];
NSPipe *pipe = [NSPipe pipe];
if (!pipe){
NSLog(@"we got to iteration %i before failing to obtain an
NSPipe instance",i);
break;
}
NSFileHandle *readHandle = [pipe fileHandleForReading];
[task setStandardOutput:pipe];
[task setLaunchPath:@"/bin/ls"];
[task setArguments:[NSArray arrayWithObject:@"/"]];
[task waitUntilExit];
[task launch];
[task release];
}
}
Without the break statement it is going to crash with an exception
where nil is being inserted into an NSDictionary, catching this
exception doesn't work. In my app I am running command line tools
in the background, and after a couple of hours I get the same
problem causing for my app to need to be relaunched. In the above
example I only need to trigger the action again, and it will work,
no relaunch required.
Why does it fail at 246, is there anything I can do differently to
remove the limit of NSPipe instances I can obtain?
I got bitten by this bug once. If I remember correctly, you're
running out of file descriptors. Try sending the readHandle a -
closeFile message; this should take care of the problem.
Glenn Z
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden