chromium之at_exit

本文介绍了AtExitManager类的使用方法及原理。AtExitManager提供了一种机制,可以在程序退出前执行注册的回调函数和单例析构操作。通过在main函数中创建AtExitManager实例,确保所有回调和析构函数在程序结束前被正确调用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// This class provides a facility similar to the CRT atexit(), except that
// we control when the callbacks are executed. Under Windows for a DLL they
// happen at a really bad time and under the loader lock. This facility is
// mostly used by base::Singleton.
//
// The usage is simple. Early in the main() or WinMain() scope create an
// AtExitManager object on the stack:
// int main(...) {
//    base::AtExitManager exit_manager;
//
// }
// When the exit_manager object goes out of scope, all the registered
// callbacks and singleton destructors will be called.

exit_manager离开作用域,所有的回调函数,单例的析构函数将会被调用。


 

再看看头文件

class AtExitManager {
 protected:
  // This constructor will allow this instance of AtExitManager to be created
  // even if one already exists.  This should only be used for testing!
  // AtExitManagers are kept on a global stack, and it will be removed during
  // destruction.  This allows you to shadow another AtExitManager.
  AtExitManager(bool shadow);

 public:
  typedef void (*AtExitCallbackType)(void*);

  AtExitManager();

  // The dtor calls all the registered callbacks. Do not try to register more
  // callbacks after this point.
  ~AtExitManager();

  // Registers the specified function to be called at exit. The prototype of
  // the callback function is void func().
  static void RegisterCallback(AtExitCallbackType func, void* param);

  // Calls the functions registered with RegisterCallback in LIFO order. It
  // is possible to register new callbacks after calling this function.
  static void ProcessCallbacksNow();

 

使用方法很简单,只要在main函数最开始的地方,定义一个即可

int main(...) 
{
   base::AtExitManager exit_manager;

   ....
}

 

转载于:https://www.cnblogs.com/ckelsel/p/9158805.html

/home/langchao/PycharmProjects/pythonProject1/.venv/bin/python /home/langchao/Desktop/pyautogui文件夹/浏览器自动化操作.py 开始登录流程... ❌ 登录失败: Timeout 10000ms exceeded. =========================== logs =========================== waiting for navigation until 'load' ============================================================ Traceback (most recent call last): File "/home/langchao/Desktop/pyautogui文件夹/浏览器自动化操作.py", line 96, in <module> browser, page = keep_session_alive() File "/home/langchao/Desktop/pyautogui文件夹/浏览器自动化操作.py", line 53, in keep_session_alive page.click("#caslogin") File "/home/langchao/PycharmProjects/pythonProject1/.venv/lib/python3.7/site-packages/playwright/_impl/_sync_base.py", line 79, in __exit__ self._event.value File "/home/langchao/PycharmProjects/pythonProject1/.venv/lib/python3.7/site-packages/playwright/_impl/_sync_base.py", line 59, in value raise exception File "/home/langchao/PycharmProjects/pythonProject1/.venv/lib/python3.7/site-packages/playwright/_impl/_frame.py", line 208, in continuation event = await wait_helper.result() playwright._impl._api_types.TimeoutError: Timeout 10000ms exceeded. =========================== logs =========================== waiting for navigation until 'load' ============================================================ Task exception was never retrieved future: <Task finished coro=<WaitHelper.reject_on_timeout.<locals>.reject() done, defined at /home/langchao/PycharmProjects/pythonProject1/.venv/lib/python3.7/site-packages/playwright/_impl/_wait_helper.py:83> exception=CancelledError()> concurrent.futures._base.CancelledError 进程已结束,退出代码为 1
最新发布
07-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值