simple win32file function calls cause python to crash

Kossay Omary kossay_omary at yahoo.com
Sat May 3 08:11:06 EDT 2003


This seems to be too simple to cause any problem. I am almost sure that the problem is in my configuration. I just cant debug it. I ran the following script and I got a message from my Windows XP that the application pthonw.exe has caused a problem and that it was killed. (I got the same behavior even when I was trying to read from a regular file and not COM3) Here is the code. It is very simple:Is there any issue with win32file under Windows XP??? import win32filedef closecom1(comhandle):
    comhandle.Close() def opencom1(filename='COM3:'):
    # returns a handle to the Windows file
    return win32file.CreateFile(filename, win32file.GENERIC_READ, \
                                0, None, win32file.OPEN_EXISTING, 0, None) def readcom1line(comhandle):
    err = 0
    char = None
    line = ''
    while err == 0 and char != '\r':
        err, char = win32file.ReadFile(comhandle, 1, None)
        if err == 0:
            if char == '\n':
                pass # eat newlines
            else:
                line = line + char
        else:
            break
    return line if __name__ == '__main__':
    # demo
    comhandle = opencom1()
    print readcom1line(comhandle)
    closecom1(comhandle)


---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20030503/b5ad0d8d/attachment.html>


More information about the Python-list mailing list