Repository: opencv
Issue: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
Labels: bug,category: highgui-gui,platform: ios/osx

I am seeing an exception on  a macOSx Sierra when running the following line:
```
    key = cv2.waitKey(1) & 0xFF
```
Any idea what could be the issue ?
```
2016-12-05 11:29:24.521 python[94697:4307308] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fffa813548b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fffbc897cad objc_exception_throw + 48
	2   AppKit                              0x00007fffa644850c -[NSApplication(NSEvent) shouldBeTreatedAsInkEvent:] + 0
	3   libopencv_highgui.2.4.dylib         0x000000010b8eb0a6 cvWaitKey + 402
	4   cv2.so                              0x000000010b0f2ce1 _ZL16pyopencv_waitKeyP7_objectS0_S0_ + 103
	5   Python                              0x000000010ac6c534 PyEval_EvalFrameEx + 14624
	6   Python                              0x000000010ac68a1e PyEval_EvalCodeEx + 1617
	7   Python                              0x000000010ac0e531 PyFunction_SetClosure + 826
	8   Python                              0x000000010abf075b PyObject_Call + 99
	9   Python                              0x000000010ac6c045 PyEval_EvalFrameEx + 13361
	10  Python                              0x000000010ac68a1e PyEval_EvalCodeEx + 1617
	11  Python                              0x000000010ac6f442 _PyEval_SliceIndex + 338
	12  Python                              0x000000010ac6beae PyEval_EvalFrameEx + 12954
	13  Python                              0x000000010ac68a1e PyEval_EvalCodeEx + 1617
	14  Python                              0x000000010ac0e531 PyFunction_SetClosure + 826
	15  Python                              0x000000010abf075b PyObject_Call + 99
	16  Python                              0x000000010ac6c045 PyEval_EvalFrameEx + 13361
	17  Python                              0x000000010ac6f4d5 _PyEval_SliceIndex + 485
	18  Python                              0x000000010ac6beae PyEval_EvalFrameEx + 12954
	19  Python                              0x000000010ac6f4d5 _PyEval_SliceIndex + 485
	20  Python                              0x000000010ac6beae PyEval_EvalFrameEx + 12954
	21  Python                              0x000000010ac68a1e PyEval_EvalCodeEx + 1617
	22  Python                              0x000000010ac0e531 PyFunction_SetClosure + 826
	23  Python                              0x000000010abf075b PyObject_Call + 99
	24  Python                              0x000000010abfb40c PyMethod_New + 1221
	25  Python                              0x000000010abf075b PyObject_Call + 99
	26  Python                              0x000000010ac6ee1b PyEval_CallObjectWithKeywords + 165
	27  Python                              0x000000010ac9bdae initthread + 2833
	28  libsystem_pthread.dylib             0x00007fffbd38daab _pthread_body + 180
	29  libsystem_pthread.dylib             0x00007fffbd38d9f7 _pthread_body + 0
	30  libsystem_pthread.dylib             0x00007fffbd38d221 thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
```