NSTask hangs if there is no running run loop
NSTask hangs if there is no running run loop
- Subject: NSTask hangs if there is no running run loop
- From: James Bucanek <email@hidden>
- Date: Wed, 11 May 2005 12:41:44 -0700
Greetings,
I've been starting an external process using NSTask. It has been working just fine, until today when I moved it to a separate thread. Now
[myTask waitUntilExit];
just hangs.
I even tried changing this to a loop
while ([myTask isRunning])
[NSThread sleep...
but I get the same results.
In my reading of NSTask, it appears that it uses notifications posted to the current run loop to determine when the task has started and stopped. But I don't have a running run loop. I started the thread using
[NSThread detachNewThread...
I tried to "wrap" a run loop around my thread, by creating a new entry point for the thread that starts a run loop. Something like this:
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; // can't have too many of these!
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
// Schedule one message to be sent, then start the loop.
// The loop should run once, then return as there are no other input sources
[runLoop performSelector:@selector(runInCurrentThread:) target:self argument:parameter order:0 modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
[runLoop run];
[pool release];
I would have thought that the run loop would start, dispatch the one pending message that I queued up in performSelector, then exit because it has nothing else to do. But it never sends the message I queued up -- it just exits immediately and does nothing.
So at this point I'm lost. I don't understand how NSTask can check for process completion without a run loop, and I don't understand how you can start a thread with a run loop that executes some arbitrary code.
--
James Bucanek <mailto:email@hidden>
_______________________________________________
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