mhammond / pywin32

Python for Windows (pywin32) Extensions
5.01k stars 792 forks source link

Missleading Errormessage for error 232 #2139

Closed JPluess closed 11 months ago

JPluess commented 11 months ago

"I recently made my first attempt with the Python pipe. It worked well as long as I used:

win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_READMODE_MESSAGE | win32pipe.PIPE_WAIT

However, when I switched to:

win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_READMODE_MESSAGE | win32pipe.PIPE_NOWAIT

I encountered misleading errors, specifically Error 232 ('Pipe being closed'). However, the actual reason for this error is that there is nothing to read. My expectation is to update Error 232 to have a more appropriate name. Alternatively, adding a new error, let's say, 'XXX: Nothing to read,' would be helpful.

Here is a snippet of my class:

python

def create_pipe(self): return win32pipe.CreateNamedPipe( r'\.\pipe\mypipe', win32pipe.PIPE_ACCESS_DUPLEX, win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_READMODE_MESSAGE | win32pipe.PIPE_NOWAIT, #PIPE_WAIT 1, 65536, 65536, 0, None)

def get_message(self) -> Dict: try:

Read data from the pipe

    (result_status, data) = win32file.ReadFile(self.pipe, self.buffer_read)
    # Check if the read was successful
    if result_status == 0:
        # Decode the received data
        received_packet = self.pkg_decode(data.decode('utf-8'))
        return received_packet
except Exception as e:
    print(e)  # Updated error message -> (232, 'ReadFile', 'The pipe is being closed.')
    return None

Pywin32, Version 306

There is even a report on stackoverflow: https://stackoverflow.com/questions/19636548/named-pipe-232-the-pipe-is-being-closed

mhammond commented 11 months ago

We can only tell you what windows tells us...