Named pipe doesn't flush in Python

I have a named pipe created using the os.mkfifo () command. I have two different Python processes that access this named pipe, process A reads and processes process B. Process A uses the select function to determine when there is data available in fifo / pipe. Despite the fact that process B is reset after each call to the record, the selection function A does not always return (it blocks, as if there was no new data). Having studied this problem extensively, I finally just programmed process B to add 5 Kbytes of garbage records before and after my actual call, and also process A was programmed to ignore these 5KB. Now everything works fine, and the selection always returns accordingly. I came to this hacker decision, noting that process A select will return if process B is to be killed (after he wrote and washed, he would have slept on the reading pipe). Is there a flash issue in Python for named pipes?

+4
source share
3 answers

What APIs are you using? os.read() and os.write() do not block anything.

+1
source

To find out if your internal Python buffering is causing your problems, when you run your scripts, instead of "python", "python -u" is executed. This will force python to enter "unbuffered mode", which will cause all output to print instantly.

+1
source

The flash operation is not related to named pipes; data for named pipes is stored strictly in memory and will not be released until it is read or FIFO is closed.

0
source

Source: https://habr.com/ru/post/1299384/


All Articles