threading issues on window close from `AutoFinish()` shell but not from `RunShadyScript()` shell

Issue #25 new
Jeremy Hill created an issue

There's a difference between

python -m Shady shell world

where the shell is created via a Shady.Console.ThreadedShell() call in Shady.Utilities.RunShadyScript(), and

python -m Shady run world

where the shell is created via a Shady.Console.ThreadedShell() call in Shady.Utilities.AutoFinish(w, shell=True) (which is not used often, but it appears in that particular script Shady/examples/world.py).

Both variants are OK if you exit the shell first. However, if you close the World first, either by pressing q or typing w.Close(), then only the RunShadyScript() variant is OK. The AutoFinish(w,shell=True) variant is not. On macOS, it crashes with a thread-related objective-C stack trace:

2019-03-14 14:49:20.312 python[56866:16573286] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1454.90/Foundation/Misc.subproj/NSUndoManager.m:361
2019-03-14 14:49:20.313 python[56866:16573286] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'

and on Windows there's no actual crash, but any matplotlib window (for example one that has been autogenerated by adding --debugTiming to the call) will be blank and will hang.

Comments (5)

  1. Jeremy Hill reporter

    Slightly changed due to semi-blind poking-around. On macOS anaconda Python 2.7 we now only get a warning on exit:

    WARNING: nextEventMatchingMask should only be called from the Main Thread! This will throw an exception in the future.
    

    On macOS anaconda Python 3.6 it used to be the same, but now under 3.7 (or at least, following complete anaconda re-install 20190815) it’s back to being a fatal crash (`libc++abi.dylib: terminating with uncaught exception of type NSException`)

    On Windows, the matplotlib window is no longer blank/unresponsive but the console does get flooded (to the point of being unusable) with Qt thread-related warnings.

  2. Log in to comment