RE: Probable Pywin32 (win32com.client) bug??

Discussion in 'Python' started by Tim Golden, Jul 15, 2004.

  1. Tim Golden

    Tim Golden Guest

    | This is a heads-up on a possible memory corruption type of bug in
    | recent and present versions of Python/win32com. I dont know if its
    | general, or specific to using win32com.client to access CDO as my
    | example does.
    |
    | My script was tiny - it just opens a MAPI/CDO session and traverses
    | the email folders - but it keeps crashing Python at random places.

    Not very helpful, but... using the standard Python 2.3.4 and the most recent
    pywin32 on my Win2K box with Outlook 2000 and Exchanhge 5.5, I can traverse
    folders via CDO without any crashes. I realise that this isn't in any way
    conclusive but if you want to post some code, I'll happily run it against
    my setup if possible to see what happens.

    I don't know if Mark H monitors python-win32 any more closely
    than c.l.py and its mirrors, but it's worth posting to that
    list as it's a win32-specific issue anyway.

    TJG


    ________________________________________________________________________
    This e-mail has been scanned for all viruses by Star Internet. The
    service is powered by MessageLabs. For more information on a proactive
    anti-virus service working around the clock, around the globe, visit:
    http://www.star.net.uk
    ________________________________________________________________________
    Tim Golden, Jul 15, 2004
    #1
    1. Advertising

  2. Tim Golden

    neblackcat Guest

    > Not very helpful, but... using the standard Python 2.3.4 and the most recent
    > pywin32 on my Win2K box with Outlook 2000 and Exchanhge 5.5, I can traverse
    > folders via CDO without any crashes. I realise that this isn't in any way
    > conclusive but if you want to post some code, I'll happily run it against
    > my setup if possible to see what happens.


    Ok thanks! I've attached the full code below.

    Basically you just point it at a profile and it runs through
    "containers" in the hierarchy (containers being infostores,
    root-folder folders, and normal folders) building up the hierarchy
    recursively.

    Each container is loaded into an MAContainerCdo object along with its
    direct sub-containers. The first one created is just a "Root"
    container which only exists to represent the top of the hierachy (ie.
    it doesnt represent any actual CDO object), but its initialisation
    causes all of the container hierarchy to be recursively loaded.

    It doesnt access any messages - just the actual folder objects. Once
    the folder hierarchy is loaded, it just dumps out the folder names
    (also recursively).

    I'm using a test profile made in OL2003, which just has a local
    Personal Message Store as I dont have an Exchange server, but I dont
    imagine that matters.

    The version below crashes on loop 21 every time I run it on my command
    line, or loop 46 if I run it in the IDE (Komodo)!

    If I comment-in the "good" lines (as commented in the following) - no
    crashes!!

    Thanks again...

    ---------------------------------------------------------------------

    import win32com.client

    #This script only reads/dumps the individual folders found in a
    specified profile, but it
    # might crash Python while doing it, so keep a backup of the relevant
    PST files just in case!

    # Set this to the Mapi/Outlook profile to use.
    sMapiProfile = "Test2"

    class MAContainerCdo:

    def __init__ (self, session, oParent=None, oCdoContainer=None):

    self.session = session
    self.oParent = oParent
    self.oChildren = []
    self.oCdoContainer = oCdoContainer

    if self.oParent is None:
    self.nLevel = 0
    self.sFullName = 'Root'
    else:
    self.nLevel = self.oParent.nLevel + 1
    self.sFullName = self.oParent.sFullName + "/" +
    self.oCdoContainer.Name

    # Get the children of this object into self.oChildren list:
    # - if its the root (level=0) then children are infostores,
    # - if its an infostore (level=1) then children are ths subfolders
    of the infostore's root folder,
    # - if its a folder (level>1) then children are folder's
    subfolders.

    if self.nLevel == 0:
    oc = self.session.InfoStores
    elif self.nLevel == 1:
    oc = self.oCdoContainer.RootFolder.Folders
    else:
    oc = self.oCdoContainer.Folders

    # THIS MAKES PYTHON CRASH (BUT NOT UNTIL LATER!)
    for o in oc:
    self.oChildren.append(MAContainerCdo(self.session, self, o))

    # THIS DOESNT (BUT IS FUNCTIONALLY IDENTICAL)!
    #if self.nLevel == 0:
    # for o in oc:
    # self.oChildren.append(MAContainerCdo(self.session, self, o))
    #else:
    # o = oc.GetFirst()
    # while o:
    # self.oChildren.append(MAContainerCdo(self.session, self, o))
    # o = oc.GetNext()


    def Dump (self):
    print "%-30s (%d children)" % (self.sFullName,
    len(self.oChildren))
    for o in self.oChildren:
    o.Dump()

    session = win32com.client.Dispatch('MAPI.Session')

    for i in range(1,100):
    print "\nLoop " + str(i)
    session.Logon(sMapiProfile)
    ocRoot = MAContainerCdo(session)
    ocRoot.Dump ()
    session.Logoff()
    neblackcat, Jul 15, 2004
    #2
    1. Advertising

  3. Tim Golden

    Mark Hammond Guest

    neblackcat wrote:

    > Ok thanks! I've attached the full code below.


    As I mentioned in private mail, I too see this crash, but the debugger
    shows it deep in CDO with no evidence of Python contributing. This
    isn't to say it is not a bug in pythoncom, but given the fairly broad
    number of applications we work well with, there isn't much I can do
    other than to call it a possible CDO bug. Even though it works with VB,
    Python and VB are sufficiently different that Python may be exercising a
    CDO code path that is rarely hit, and therefore rarely seen.
    Unfortunately, the same may also be true in reverse.

    Mark.
    Mark Hammond, Jul 19, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. neblackcat
    Replies:
    0
    Views:
    391
    neblackcat
    Jul 15, 2004
  2. Replies:
    0
    Views:
    371
  3. Pierre Quentel
    Replies:
    21
    Views:
    665
  4. Ronald Fischer
    Replies:
    0
    Views:
    115
    Ronald Fischer
    Jun 18, 2007
  5. Ruby Quiz

    [QUIZ] Probable Iterations (#141)

    Ruby Quiz, Sep 28, 2007, in forum: Ruby
    Replies:
    14
    Views:
    215
    Eugene Kalenkovich
    Oct 4, 2007
Loading...

Share This Page