On Jul 25, 2013, at 8:24 AM, Martin Hewitson <martin.hewit...@aei.mpg.de> wrote:

> Dear list,
> 
> I have a couple of users reporting exceptions (and crashes) which I think are 
> associated with my interrupting an NSTask when they close a document. I get 
> exceptions like this:
> 
> *** -[NSConcreteTask interrupt]: task not launched
> 
> In the code I do the following to cancel the NSTask when the document is 
> closed:
> 
>  if (self.typesetTask != nil) {
>    if ([self.typesetTask isRunning] == YES) {
>      [self.typesetTask terminate];
>    }
>    self.typesetTask = nil;
>  }


First two things I'd do:

- search the code to confirm you're never calling interrupt directly

- put some debugging around your calls to launch, log just before & after the 
call, or catch exceptions and log them, or whatever fits with your style & 
debugging support functions, to make sure you're not having some problems at 
launch, or log them if they occur

Then:

By the time terminate does its thing, the task might not be still running. But 
a good API design would not throw an exception for that, and in fact, the docs 
say that terminate has no effect if the task has already launched and finished. 
Also "not launched" is certainly not a good message for "launched, ran, 
completed, therefore no longer launched at this time". So I really doubt that's 
your problem. 

In fact, I really do suspect that exception might actually be thrown when you 
try to launch the task. I seem to recall having seen this kind of exception 
when a task had failed to launch, with the "task not launched" being accurate, 
but the [… interrupt] being misleading to me.

But, that said, ***IF*** the docs are wrong and/or there is a bug, and the 
exception gets thrown because the process ends between the time you check 
isRunning and the time that terminate gets called, then typesetTask does not 
get set to nil. It seems that you're either using properties to handle 
retain/release, or ARC here, so it's not like it would be a pointer to a 
deallocated object. But ***MAYBE*** you're then using it in a way that is 
inappropriate for a task that has completed, and crashing there.

That's all very tenuous, but it's (barely) worth a try, as a debugging measure, 
catching exceptions from that terminate call in order to make sure the property 
gets set to nil, because it can't hurt, and there's some tiny chance it will 
help.

And of course you should make sure that you don't have some dumb bug that 
overwrites typesetTask between the time you launch it and try to terminate it 
;-)

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to