2

似乎 wxPython 正在以一种阻止上下文管理器__exit__调用发生的方式拦截任何 SIGINT。有没有办法解决这种行为?

这是一个演示该问题的小型测试程序:

import wx
import time

class Printer(object):
    def __enter__(self):
        return self
    def __exit__(self, x, y, z):
        print('### Context manager called!')

with Printer() as p:
    app = wx.App()
    frame = wx.Frame(None)
    frame.Show()
    app.MainLoop()
    #time.sleep(1000)

如果像这样运行它并按 Ctrl+C,则不会生成任何输出。如果将 wx 代码更改为 sleep 语句并按 Ctrl+C,则上下文管理器会执行预期的操作。

4

0 回答 0