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

Pygame window not closing in jupyter notebook (window hangs) #2256

Open
pseudo-rnd-thoughts opened this issue Jun 16, 2023 · 2 comments
Open
Labels
bug Not working as intended macOS

Comments

@pseudo-rnd-thoughts
Copy link

Environment:

  • Operating system (e.g. Windows, Linux(Debian), Linux(Ubuntu), Mac): Mac
  • Python version (e.g. 3.7.9, 3.8.5) : 3.9
  • SDL version (e.g. SDL 2.0.12): 2.26.4
  • PyGame version (e.g. 2.0.0.dev10, 1.9.6): 2.4.0 (and 2.1.3)
  • Relevant hardware (e.g. if reporting a bug about a controller, tell us the brand & name of it):

Current behavior:

I'm part of the development team of OpenAI Gym and Gymnasium and would like users to be able to use pygame in jupyter notebook.
We are able to open a window in jupyter notebook however pygame.quit doesn't cause the window to close and the kernel will hang and close

Expected behavior:

To be able to close a pygame windows in jupyter notebook

Steps to reproduce:

pip install gymnasium[classic_control]

import gymnasium as gym

env = gym.make("LunarLander-v2", render_mode="human")
observation, info = env.reset()

for _ in range(100):
   action = env.action_space.sample()
   observation, reward, terminated, truncated, info = env.step(action)

   if terminated or truncated:
      observation, info = env.reset()
env.close()  # This includes `pygame.quit()` 

I have tested this is issue with pygame using the following basic script

import pygame

win = pygame.display.set_mode((500,500))
pygame.display.set_caption("First Game")

run = True
while run:
    pygame.time.delay(100)

    # handle events
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    # clear the disaply
    win.fill(0)

    # draw the scene
    filled_rect = pygame.Rect(100, 100, 25, 25)
    pygame.draw.rect(win, (0,0,255), filled_rect)

    # update the dispaly
    pygame.display.update()

pygame.quit()
@Starbuck5
Copy link
Member

Hello, thanks for the issue.

I was unable to replicate this on my Windows computer, I can dig up a Mac and see about that sometime.

@pseudo-rnd-thoughts
Copy link
Author

From reports with users, I suspect that this is a mac only issue

@Starbuck5 Starbuck5 added the macOS label Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended macOS
Projects
None yet
Development

No branches or pull requests

2 participants