I'm working with named pipes (fifo) to communicate between python and MATLAB. The MATLAB code to read from the pipe is functional but it hangs if nothing has been written to the fifo. I would prefer it would gracefully timeout when no data is available.
If the pipe exists (in bash):
$ mkfifo pipe_read
but has no data the MATLAB open command:
>> fid = fopen('pipe_read', 'r');
hangs until data is available:
$ echo "test data" >> pipe_read
Rather than blocking forever I would like fopen to return a file-id that indicates an error (i.e. similar to -1 as it does when the file does not exist) if there is no data available.
Could there be a solution similar to the asynchronous reads available in the commands for writing and reading to serial instruments: http://www.mathworks.com/help/matlab/ref/readasync.html ?
Or possibly fopen could be embedded into a matlab timer object that enables a timeout?
This has been asked before but without an answer: Matlab read from named pipe (fifo)
fopenalready freezing? I would expectfreadand similar to freeze. The functionreadasyncis related to serial ports, unless you use java I don't know any possibility to read/write files asynchron in matlab. - Danielfopenfreezes such that I don't even get to anfscanforfread. - ljk07