简体   繁体   English

我的 jupyter 笔记本 kernel 经常死于这个 pygame 代码

[英]My jupyter notebook kernel often dies from this pygame code

I wrote a pygame code like this.我写了一个像这样的 pygame 代码。

pygame.init()
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("Test")
black = (0, 0, 0)
sysfont = pygame.font.SysFont(None, 50)
win.fill((255, 255, 255))

running = True
while running:
    win.fill((255, 255, 255))
    digit = sysfont.render("Test", 1, black)
    win.blit(digit, (50, 50))
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            
pygame.quit()

So That's just to create a window and show some text on it.所以这只是创建一个 window 并在上面显示一些文本。 I runned it on Jupyter Notebook and it worked.我在 Jupyter Notebook 上运行它,它工作正常。 but when I closed the window and tried to run it again, a window came up but closed of itself and Jupyter said "The kernel appears to have died."但是当我关闭 window 并尝试再次运行它时,出现了 window 但自行关闭,Jupyter 说“kernel 似乎已经死了。” This happened again and again.这种情况一次又一次地发生。 I runned it, it worked.我运行它,它工作。 but I rerunned it, it failed.但我重新运行它,它失败了。 Is there anything wrong with this code?这段代码有什么问题吗?

I think it's an issue with Anaconda, as the same issue has been faced by me in spyder kernel.我认为这是 Anaconda 的问题,因为我在 spyder kernel 中也遇到了同样的问题。 For spyder it restarts the kernel, which is a little time taking but i don't think there exists a solution for the same.对于 spyder,它会重新启动 kernel,这需要一点时间,但我认为没有相同的解决方案。

I hope you're safe in this time of an ongoing pandemic!我希望你在这个持续流行的流行病时期是安全的!

I faced the same problem, and I kind of addressed it by stopping the kernel instead of exiting the pygame.我遇到了同样的问题,我通过停止 kernel 而不是退出 pygame 来解决它。 when I stop the kernel, the pygame windows also stoped and in the next run, it starts without killing the kernel.当我停止 kernel 时,pygame windows 也停止了,在下一次运行中,它在没有杀死 Z39D84C1921AFDA 的情况下启动。 Hope it help.希望它有所帮助。

I bypassed this problem by adding %reset -f at the first line before all the import statements.我通过在所有导入语句之前的第一行添加%reset -f绕过了这个问题。 I can run and close the window without the dead kernel prompt.我可以运行并关闭 window 而没有死 kernel 提示。 Hopefully this helps people looking for this kind of solution.希望这可以帮助人们寻找这种解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM