Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSInternalInconsistencyException Error #14

Open
ss2342 opened this issue Sep 4, 2023 · 8 comments
Open

NSInternalInconsistencyException Error #14

ss2342 opened this issue Sep 4, 2023 · 8 comments

Comments

@ss2342
Copy link

ss2342 commented Sep 4, 2023

I cloned this repo and tried to run the code via streamlit but keep running into this issue on my Mac:

2023-09-04 11:32:27.017 Python[63562:3191072] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'

Streamlit will just disconnect

I tried to do a workaround by using docker but I run into a seg fault.

@edsaac
Copy link
Owner

edsaac commented Sep 5, 2023

@Ssingh1997, no clue what NSInternalInconsistencyException is about.

The segfaulting you get in docker is probably due not having a display server. Check below how to start one using pyvista:
https://docs.pyvista.org/version/stable/api/utilities/_autosummary/pyvista.start_xvfb.html

And see here how I got it running on Streamlit Community Cloud, another headless machine.
https://github.com/edsaac/stpyvista-tests/blob/c2305a079a10ac15de96c30291b18809c9c0bd76/%F0%9F%A7%8A_stpyvista.py#L9-L18

@villanuevab
Copy link

villanuevab commented Sep 14, 2023

I get a similar error when attempting to use the example code.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow should only be instantiated on the main thread!' 
***

This is with

import pyvista as pv
pv.start_xvfb()
from stpyvista import stpyvista

## Initialize a plotter object
plotter = pv.Plotter(window_size=[400,400])

## Create a mesh with a cube
mesh = pv.Cube(center=(0,0,0))

## Add some scalar field associated to the mesh
mesh['myscalar'] = mesh.points[:, 2]*mesh.points[:, 0]

## Add mesh to the plotter
plotter.add_mesh(mesh, scalars='myscalar', cmap='bwr', line_width=1)

## Final touches
plotter.view_isometric()
plotter.add_scalar_bar()
plotter.background_color = 'white'

## Pass a key to avoid re-rendering at each time something changes in the page
stpyvista(plotter, key="pv_cube")

@GarrickLin
Copy link

GarrickLin commented Oct 25, 2023

got similar error on mac

 You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://192.168.6.17:8501

2023-10-25 19:20:32.191 python[28750:16576785] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
        0   CoreFoundation                      0x0000000198acf154 __exceptionPreprocess + 176
        1   libobjc.A.dylib                     0x00000001985ee4d4 objc_exception_throw + 60
        2   CoreFoundation                      0x0000000198af83a0 _CFBundleGetValueForInfoKey + 0
        3   AppKit                              0x000000019bc9e638 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 320
        4   AppKit                              0x000000019bc8c90c -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 816
        5   AppKit                              0x000000019bc8c5d0 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 48
        6   libvtkRenderingOpenGL2-9.2.dylib    0x000000016c6fbe4c _ZN20vtkCocoaRenderWindow13CreateAWindowEv + 1488
        7   libvtkRenderingOpenGL2-9.2.dylib    0x000000016c78dd5c _ZN21vtkOpenGLRenderWindow5StartEv + 40
        8   libvtkRenderingOpenGL2-9.2.dylib    0x000000016c6fc4c4 _ZN20vtkCocoaRenderWindow5StartEv + 20
        9   libvtkRenderingUI-9.2.dylib         0x00000001561d9488 _ZN30vtkCocoaRenderWindowInteractor10InitializeEv + 64
        10  libvtkRenderingCore-9.2.dylib       0x0000000156f590c0 _ZN15vtkRenderWindow6RenderEv + 148
        11  libvtkRenderingOpenGL2-9.2.dylib    0x000000016c7901d4 _ZN21vtkOpenGLRenderWindow6RenderEv + 112
        12  vtkRenderingOpenGL2.cpython-310-dar 0x000000016c94e850 _ZL30PyvtkOpenGLRenderWindow_RenderP7_objectS0_ + 104
        13  python3.10                          0x00000001007d6bb0 cfunction_call + 96
        14  python3.10                          0x00000001007746c8 _PyObject_MakeTpCall + 136
        15  python3.10                          0x00000001008a7f78 call_function + 380
        16  python3.10                          0x000000010089fd80 _PyEval_EvalFrameDefault + 23352
        17  python3.10                          0x000000010089898c _PyEval_Vector + 392
        18  python3.10                          0x00000001008a7e80 call_function + 132
        19  python3.10                          0x000000010089ee84 _PyEval_EvalFrameDefault + 19516
        20  python3.10                          0x000000010089898c _PyEval_Vector + 392
        21  python3.10                          0x00000001007785dc method_vectorcall + 124
        22  python3.10                          0x00000001008a7e80 call_function + 132
        23  python3.10                          0x000000010089e4b0 _PyEval_EvalFrameDefault + 17000
        24  python3.10                          0x000000010089898c _PyEval_Vector + 392
        25  python3.10                          0x00000001008a7e80 call_function + 132
        26  python3.10                          0x000000010089ee84 _PyEval_EvalFrameDefault + 19516
        27  python3.10                          0x000000010089898c _PyEval_Vector + 392
        28  python3.10                          0x00000001008a7e80 call_function + 132
        29  python3.10                          0x000000010089ee84 _PyEval_EvalFrameDefault + 19516
        30  python3.10                          0x000000010089898c _PyEval_Vector + 392
        31  python3.10                          0x000000010089abf0 _PyEval_EvalFrameDefault + 2472
        32  python3.10                          0x000000010089898c _PyEval_Vector + 392
        33  python3.10                          0x00000001007785dc method_vectorcall + 124
        34  python3.10                          0x00000001008a7e80 call_function + 132
        35  python3.10                          0x000000010089e4b0 _PyEval_EvalFrameDefault + 17000
        36  python3.10                          0x000000010089898c _PyEval_Vector + 392
        37  python3.10                          0x00000001008a7e80 call_function + 132
        38  python3.10                          0x000000010089e4b0 _PyEval_EvalFrameDefault + 17000
        39  python3.10                          0x000000010089898c _PyEval_Vector + 392
        40  python3.10                          0x00000001008a7e80 call_function + 132
        41  python3.10                          0x000000010089e430 _PyEval_EvalFrameDefault + 16872
        42  python3.10                          0x000000010089898c _PyEval_Vector + 392
        43  python3.10                          0x0000000100892d78 builtin_exec + 304
        44  python3.10                          0x00000001007d73e8 cfunction_vectorcall_FASTCALL + 88
        45  python3.10                          0x00000001008a7e80 call_function + 132
        46  python3.10                          0x000000010089e430 _PyEval_EvalFrameDefault + 16872
        47  python3.10                          0x000000010089898c _PyEval_Vector + 392
        48  python3.10                          0x00000001008a7e80 call_function + 132
        49  python3.10                          0x000000010089ee84 _PyEval_EvalFrameDefault + 19516
        50  python3.10                          0x000000010089898c _PyEval_Vector + 392
        51  python3.10                          0x00000001007786e4 method_vectorcall + 388
        52  python3.10                          0x000000010089abf0 _PyEval_EvalFrameDefault + 2472
        53  python3.10                          0x000000010089898c _PyEval_Vector + 392
        54  python3.10                          0x00000001008a7e80 call_function + 132
        55  python3.10                          0x000000010089ee84 _PyEval_EvalFrameDefault + 19516
        56  python3.10                          0x000000010089898c _PyEval_Vector + 392
        57  python3.10                          0x00000001008a7e80 call_function + 132
        58  python3.10                          0x000000010089ee84 _PyEval_EvalFrameDefault + 19516
        59  python3.10                          0x000000010089898c _PyEval_Vector + 392
        60  python3.10                          0x00000001007786e4 method_vectorcall + 388
        61  python3.10                          0x0000000100992e34 thread_run + 172
        62  python3.10                          0x000000010091a32c pythread_wrapper + 48
        63  libsystem_pthread.dylib             0x0000000198977fa8 _pthread_start + 148
        64  libsystem_pthread.dylib             0x0000000198972da0 thread_start + 8
)
libc++abi: terminating due to uncaught exception of type NSException
[1]    28750 abort      streamlit run pyvista_test.py

with the simple code:

def demo():
    # Initialize a plotter object
    plotter = pv.Plotter(window_size=[400, 400])

    # Create a mesh with a cube
    mesh = pv.Cube(center=(0, 0, 0))

    # Add some scalar field associated to the mesh
    mesh['myscalar'] = mesh.points[:, 2]*mesh.points[:, 0]

    # Add mesh to the plotter
    plotter.add_mesh(mesh, scalars='myscalar', cmap='bwr', line_width=1)

    # Final touches
    plotter.view_isometric()
    plotter.add_scalar_bar()
    plotter.background_color = 'white'

    # Pass a key to avoid re-rendering at each time something changes in the page
    stpyvista(plotter, key="pv_cube")

@anabiman
Copy link

I am receiving a similar error on mac os v14.2.1:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow should only be instantiated on the main thread!'

  • python version: 3.11.7
  • panel version: 1.3.8
  • streamlit version: 1.30.0
  • stpyvista version: 0.0.14
  • pyvista version: 0.43.2

@Yemeen
Copy link

Yemeen commented Jun 2, 2024

same thing here with example code on m2 mac, python 3.11.9, PyVista 0.43.8, stpyvista 0.0.17.

@dwromero
Copy link

@edsaac Could you please help us out? Has somebody solved the problem?

@edsaac
Copy link
Owner

edsaac commented Aug 12, 2024

This issue appears to be iOS specific so I am not able to replicate it. iOS was just recently added as a supported platform to CPython (PEP 719), so maybe test using the current candidate release for Python 3.13?

Of course, if someone finds a solution to the problem, lmk and I will patch stpyvista accordingly 😉

@Yemeen
Copy link

Yemeen commented Aug 12, 2024

Tried using off screen rendering by setting pv.OFF_SCREEN = True and plotter.off_screen = True, but didn't work.

I also tried forcing rendering on the main thread and using Streamlit's st.cache_resource to ensure plotter creation on the main thread.

Someone with more resources could maybe try a new render method instead of panel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants