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

Menu Quit Error : SystemExit on VS Code #251

Closed
BackMountainDevil opened this issue Jan 14, 2021 · 6 comments · Fixed by #257
Closed

Menu Quit Error : SystemExit on VS Code #251

BackMountainDevil opened this issue Jan 14, 2021 · 6 comments · Fixed by #257
Labels

Comments

@BackMountainDevil
Copy link

BackMountainDevil commented Jan 14, 2021

Env

  • win 10 amd64
  • Visual Studio Code: .51.1
  • python 3.9.0
  • pygame 2.0.1
  • pygame-menu 3.4.4

Error

code

import pygame
import pygame_menu

pygame.init()
surface = pygame.display.set_mode((600, 400))


def set_difficulty(value, difficulty):
    pass


def start_the_game():
    pass


menu = pygame_menu.Menu(300,
                        400,
                        'Welcome',
                        theme=pygame_menu.themes.THEME_BLUE)

menu.add_text_input('Name :', default='John Doe')
menu.add_selector('Difficulty :', [('Hard', 1), ('Easy', 2)],
                  onchange=set_difficulty)
menu.add_button('Play', start_the_game)
menu.add_button('Quit', pygame_menu.events.EXIT)
menu.mainloop(surface)

desc by VS Code

When I click the last menuitem called "QUIT", it just call this exception error

发生异常: SystemExit  
  File "D:\Documents\CAU\Lion\repositiries\Python\temp\tmp.py", line 32, in <module>
    menu.mainloop(surface)

Then I try to replace pygame_menu.events.EXIT with exit(0) or pygame_menu.events.close, but it does't help.

@ppizarror
Copy link
Owner

how do you run your script? I can't manage to get this same error even with tests

@ppizarror
Copy link
Owner

Exit event call the following:

pygame.quit()
sys.exit()

@ppizarror
Copy link
Owner

Maybe sys.exit() is the problem. I think using os._exit(1) should fix the issue

@ppizarror
Copy link
Owner

ppizarror commented Jan 14, 2021

I think this fixes the issue, but sadly I cannot test...

def _exit(self):
    """
    Internal exit function.

    :return: None
    """
    self.disable()
    pygame.quit()
    try:
        sys.exit(0)
    except SystemExit:
        os._exit(1)

@BackMountainDevil
Copy link
Author

bad code

# None of this can fixed that situation
menu.add_button('Quit', exit(0))
menu.add_button('Quit', pygame.quit())
menu.add_button('Quit', sys.exit(0))
menu.add_button('Quit', os._exit(1))

how I run my script

Run the example code by VS Code with extension called ms-python.python invented by Microsoft. Press F5 to run it. BREAKPOINTS contens of Raised Exceptions and Uncaught Exception. Only when click the Quit button in the menu will occur that - Exception has occurred: SystemExit.
If I run the code in VS Code with ms-python.python extension, it will cause an exception.

some temp work

  • If I run the code with terminal - python tmp.py, it work fine.
  • If I run the code in VS Code with ms-python.python extension, and canel both BREAKPOINTS, it work fine, no more exception.
  • this code work fine
def quitgame():
    # do things
    exit(0)

menu.add_button('Quit', quitgame)

@BackMountainDevil
Copy link
Author

New verison 3.5.1 work well. You guys really do a good thing
No matter use which one (PYGAME_QUIT, PYGAME_WINDOWCLOSE) does work. Thanks

@ppizarror ppizarror added the bug label Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants