你怎么能保证注册的atexit函数将AppHelper.runEventLoop()在PyObjC运行?

StackOverflow https://stackoverflow.com/questions/1255025

  •  12-09-2019
  •  | 
  •  

我只是想知道为什么我在我注册了一个atexit对功能... e.g。

import atexit
atexit.register(somefunc)
...
AppHelper.runEventLoop()

当然,我知道什么时候会atexit将无法正常工作。当我注释掉AppHelper.runEventLoop()atexit函数被调用。我也浏览我的pyobjc鸡蛋,我__init__.py包下下objc看到下面的代码:

import atexit
atexit.register(recycleAutoreleasePool)

我寻找无济于事蛋内的任何参考。我也试过围绕一个try-finally各地AppHelper.runEventLoop()外壳,并在finally块中的命令将不会被调用。

希望有人可以帮助我在这里。

P.S。假设我不想使用应用程序委托的applicationShouldTerminate:方法...

有帮助吗?

解决方案

我相信你确实需要委托,否则事件循环可以冷不丁退出过程(有点像os._exit),因此没有给Python运行时有机会运行终止代码如finally条款,atexit功能,等等等等

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top