0

Under Windows 7 I have a Python 3 application which communicates via named pipe with an executable, written in C using Visual Studio. Within Python I'm using win32pipe package.

I observe that within the executable reading from pipe is blocking:

readResult = ReadFile(plafParams->hrpipe_p, &byte, 1, &dwBytesTransferred, &overlap);

The pipe is opened with:

...
...
overlap.hEvent = NULL;
overlap.Offset = 0;
overlap.OffsetHigh = 0;
overlap.Pointer = NULL;
...
...
plafParams->hwpipe_p = CreateFile(pipeName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, &overlap);

overlap is a static global variable and initialized as above.

OVERLAPPED overlap;

In Python the pipe is opened like:

self._rpipe = win32pipe.CreateNamedPipe(r'\\.\pipe\wskr_%s'%(self._comport,), win32pipe.PIPE_ACCESS_DUPLEX | win32file.FILE_FLAG_OVERLAPPED , 0, 1, 256, 256, 0, None)

After waiting for connection to the pipe, I write to it like

win32file.WriteFile(self._rpipe, bytes)

It works, and I get the sent bytes in the executable without problems, but I would like to have a non-blocking read. Therefore I opened the pipe with win32file.FILE_FLAG_OVERLAPPED, but that doesn't help...

I would appreciate any hint ;-)

MichaelW
  • 1,328
  • 1
  • 15
  • 32
  • 1
    1: You don't pass the `OEVERLAPPED` pointer to `CreateFile`. Take a look at https://stackoverflow.com/questions/49799109/win32file-readdirectorychangesw-doesnt-find-all-moved-files/49888600#49888600, (search for **async**). It's not about pipes, but the principle is the same. – CristiFati Apr 26 '18 at 10:06
  • in C or python? In C I pass it as a pointer (&overlap), in Python I use CreateNamedPipe as described. Where do you mean exactly? – MichaelW Apr 26 '18 at 12:21
  • In *C* or *Python*. It's wrong. *Python* is just a wrapper over *C*. you pass `overlapped` to `ReadFile`. – CristiFati Apr 26 '18 at 14:24
  • in C I pass overlap structure both for ReadFile and writeFile. In python however, I don't know: is there also an overlap structure I would have to pass along? The WriteFile doesn't have an argument for that. – MichaelW Apr 27 '18 at 07:48
  • The link I sent in my 1st message, also contains some urls to documentation (besides a non blocking example). By playing with them you could reach to what's useful to you. Or maybe you're just waiting for someone to provide the code... – CristiFati Apr 27 '18 at 12:59

0 Answers0