Reputation: 5806
Whenever I cancelAllOperations()
I get this wonder message:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSOperationInternal _start:]: something is trying to start the receiver simultaneously from more than one thread' *** First throw call stack: (0x1935321c0 0x191f6c55c 0x193532108 0x193f2b788 0x193ff8b00 0x1923bd1c0 0x1923cb444 0x1923c09a8 0x1923cd38c 0x1923cd0ec 0x1925c62b8 0x1925c5da4) libc++abi.dylib: terminating with uncaught exception of type NSException
This could not possibly be the very same bug discovered in 2008 in OSX and described here https://www.mikeash.com/pyblog/dont-use-nsoperationqueue.html ?
Though in my case this is a zero effort occurence: trips all the time.
This accompanied by <myoperationnameishere> 0x17425e240 went isFinished=YES without being started by the queue it is in
There is a huge number of operation types so I'm not listing them here.
However, all of them are derived from this class.
public class AsynchronousOperation: NSOperation {
// MARK: - Types
public enum State {
case Ready, Executing, Finished
func keyPath() -> String {
switch self {
case Ready:
return "isReady"
case Executing:
return "isExecuting"
case Finished:
return "isFinished"
}
}
}
public override init() {
state = State.Ready
super.init()
}
// MARK: - Properties
public var state = State.Ready {
willSet {
willChangeValueForKey(newValue.keyPath())
willChangeValueForKey(state.keyPath())
}
didSet {
Util.log("\(self.dynamicType) \(oldValue) -> \(state)", dc: [.Operation])
didChangeValueForKey(oldValue.keyPath())
didChangeValueForKey(state.keyPath())
}
}
// MARK: - NSOperation
override public var ready: Bool {
return super.ready && state == .Ready
}
override public var executing: Bool {
return state == .Executing
}
override public var finished: Bool {
return state == .Finished
}
public override func cancel() {
super.cancel()
state = .Finished
}
}
Upvotes: 2
Views: 1214
Reputation: 5806
This accompanied by 0x17425e240 went isFinished=YES without being started by the queue it is in
was the clue. as well as this: NSOperationQueue not working in IOS5
I was setting isfinished to true in the cancel() method overridden in the operations further down the inheritance tree
and this is not correct for operations being cancelled that have not yet been started
now that this is taken care of the alarm bells are off
Upvotes: 3