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

Allow the user to close the viewer by clicking on the x close button on the window without producing a SystemExit error #10

Open
dsleiter opened this issue Dec 1, 2022 · 3 comments

Comments

@dsleiter
Copy link
Contributor

dsleiter commented Dec 1, 2022

Steps to reproduce:

  1. start the viewer from within a notebook
  2. click on the x in the viewer gui to close the window

The following error is printed inside the notebook:

An exception has occurred, use %tb to see the full traceback.

SystemExit
/Users/darin/miniconda3/envs/cerebro/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3441: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
@Ln11211
Copy link

Ln11211 commented Dec 30, 2022

Hey there, I looked into this and I found that Panda uses sys.exit() so the error is inevitable. Here is the link to extended traceback
https://pastebin.com/CyzifM4V

I guess we can handle the exception using a try block in the renderer.py like this,
image

@dsleiter
Copy link
Contributor Author

dsleiter commented Jan 9, 2023

Thanks for the investigative work @Ln11211!

Catching the SystemExit seems like it would work as a short-term work-around, but I'd be worried about potential side effects. What should happen if the application was called via a script rather than from a notebook? What should happen if there was an error and sys.exit was called with a non-zero error from another part of the ShowBase?

Looking at pandas documentation, it seems like the function which calls sys.exit() is made to be overridden (since it says "the default implementation...")
https://docs.panda3d.org/1.10/python/reference/direct.showbase.ShowBase#direct.showbase.ShowBase.ShowBase.finalizeExit
So we could maybe override finalizeExit or another exit function it in Cerebro_window with some other behavior.

Does Panda3D documentation give any guidance on implementing exit functionality?

@Ln11211
Copy link

Ln11211 commented Jan 11, 2023

Hey @dsleiter , after looking further into this issue, I understood that this behavior of the viewer is only specific to notebooks and there is a further breakdown of the viewer when we try to run the script right after we close it,
Exception: Attempt to spawn multiple ShowBase instances!
And the Kernel dies. This has nothing to do with Cerebro, but everything to do with the 'Sys.exit()'

Steps to reproduce

  1. Run the script (code cell) once in a notebook
  2. close it using the gui
  3. Run the script again(cell)

traceback
I have attached the traceback and also a Stack overflow thread that address the same issue.

TLDR

This weird breakdown of the Panda is only due to the Sys.exit() and happens only in notebooks and not in Terminal. After the initial SystemExit exception, the Panda breaks down when tried to run again. Read the StackOverflow thread for detailed explanation.

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

2 participants