【问题标题】:Outlook becomes slow after using python win32com package to read emails使用 python win32com 包阅读邮件后 Outlook 变慢
【发布时间】:2020-10-06 05:37:16
【问题描述】:

当我使用win32com 访问outlook 2013 时,运行代码后我的outlook 明显变慢。以下是我的代码:

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
                                    # the inbox. You can change that number to reference
                                    # any other folder
emails = outlook.GetDefaultFolder(6).Folders['xyz'].Folders['abc'].Items

如果预先打开 Outlook,有时我会收到 com_error: (-2146959355, 'Server execution failed', None, None) 运行代码。我将不得不重新启动 Outlook 并重置我的 python 环境以恢复正常。阅读邮件后是否需要在outlook中进行任何设置或任何特殊的python操作?

最好的问候, 杰里米

【问题讨论】:

  • 您是否有理由在第 2 行声明收件箱,然后在第 5 行不使用它?我的直接想法是你的泄漏对象......
  • 您曾经退出过 win32com 应用程序吗?如果它仍然与计算机上的其他程序一起运行,它会占用内存/其他资源并使您原来的 Outlook 速度变慢。
  • @Evgeny - Outlook 是一个单例,任何时候只有一个实例运行。检查任务管理器
  • 那是你的完整代码吗?您如何处理电子邮件集合?

标签: python outlook win32com


【解决方案1】:

您曾经退出过 win32com 应用程序吗?如果它仍然与计算机上的其他程序一起运行,它会占用内存/其他资源并使您原来的 Outlook 速度变慢,这是我的猜测。

我确实运行类似的 Word 应用程序

def win32_word_dispatch():
    # Lazy import of win32com - do not load Windows/MS Office libraries when
    # they are not called.
    import win32com.client as win32
    word = win32.Dispatch("Word.Application")
    word.Visible = 0
    return word

并尝试将其关闭为:

def close_ms_word(app):
    app.Quit()
    # ISSUE: must also quit somewhere by calling app.Quit()
    # like in
    # http://bytes.com/topic/python/answers/23946-closing-excel-application

【讨论】:

  • Outlook 是单例的,任何时候都只运行一个实例。检查任务管理器
猜你喜欢
  • 2014-05-13
  • 2019-02-17
  • 2018-03-18
  • 2023-01-26
  • 1970-01-01
  • 2018-10-27
  • 1970-01-01
  • 2017-05-25
  • 2015-11-19
相关资源
最近更新 更多