python - Named pipe race condition? -


i have 2 processes 1 c , 1 python. c process spends time passing data named pipe python process reads. should pretty simple , works fine when i'm passing data (currently time stamp such "mon aug 19 18:30:59 2013") once per second.

problems occur when take out sleep(1); command in c process. when there's no 1 second delay communication gets screwed up. python process read more 1 message or report has read data though buffer empty. @ point c process bombs.

before go posting sample code i'm wondering if need implement sort of synchronisation on both sides. maybe telling c process not write fifo if it's not empty?

the c process opens named pipe write , python process opens read only.

both processes intended run loops. c process continually reads data comes in on usb port , python process takes each "message" , parses before sending sql db.

if i'm going looking @ 50 messages per second, named pipes able handle level of transaction rate? size of each transaction relatively small (20 bytes or so) frequency makes me wonder if should looking @ other form of inter-process communication such shared memory?

any advice appreciated. can post code if necessary @ moment i'm wondering if should syncing between 2 processes somehow.

thanks!

a pipe stream.

the number of write() calls on sender side not need correspond number of read()s on receiver's side.

try implement sort of synchronisation protocol.

if sending plain text example adding new-lines between each token , make receiver read until 1 of such found.

alternatively prefix each data sent, fixed length number representing amount of data come. receiver can parse format.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -