2016-12-09 25 views
0

:win32com.client.DispatchWithEvents 나는 다음과 같은 코드를 사용하여 동시에 2 개 개의 별도의받은 편지함에 OnItemAdd 이벤트를 수신하기 위해 노력하고

class Handler_Class(): 
     def OnItemAdd(self, mail): 
      #Check if the item is of the MailItem type 
      if mail.Class==43: 
       print(mail.Subject, " - ", mail.Parent.FolderPath) 
    inboxes = ["inbox1", "inbox2"] 
    for inbox in inboxes: 
     items = win32com.client.DispatchEx("Outlook.Application").GetNamespace("MAPI").Folders[inbox].Folders["Inbox"].Items 
     win32com.client.DispatchWithEvents(items, Handler_Class) 
    print(datetime.now(),"Ready to pump") 
    pythoncom.PumpMessages() 

pythoncom.PumpMessages() 그래도 작동하지 않습니다. 하나의받은 편지함 항목 만 수신하도록 코드를 리팩터링하면 작동합니다.

해결 방법에 대한 아이디어가 있으십니까?

답변

0

이것은 불가능합니다. 모든 스레드 코드에서 모든 DispatchWithEvents 객체를 초기화하고이를 pythoncom.PumpMessages()로 캡핑하면됩니다.

이렇게하면 여러 개의받은 편지함에있는 ItemAdd와 같은 이벤트를 동시에들을 수 있습니다.