VsCode wxPython 应用本应停止时似乎仍保留 运行

VsCode appears to keep running wxPython app when it should have stopped

在我的 VsCode wxPython 应用程序 Windows 下,我将关闭事件绑定到我的函数,如下所示:

import wx

class MyFrame(wx.Frame):
    def __init__(self, title):
        wx.Frame.__init__(self, None, title = title, pos = (150, 0))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        # Other stuff ...

    def OnClose(self, event):
        print("closing")
        self.Destroy()

app = wx.App()
top = MyFrame("My App")
top.Show()
app.MainLoop()
print("done")

现在我可以看到当我关闭顶层window(一个wxFrame)作为closingdone 消息出现。 window 本身也消失了。

但是 VsCode 认为该应用程序仍处于 运行ning 状态,因为它的调试控件仍然可用:

并且 运行 它的控制台(Python 调试控制台)不会返回提示。直到我单击停止按钮,命令提示符才重新出现在该控制台中。

有趣的是,如果我 运行 VsCode 的 外部 应用程序,它会正确退出,返回到命令提示符。

试试 wx.Exit() 以防你有一些东西 open/running 而没有意识到。

wx.Exit() Exits application after calling wx.App.OnExit .

Should only be used in an emergency: normally the top-level frame should be deleted (after deleting all other frames) to terminate the application. See wx.CloseEvent and wx.App.