skywind3000 wrote:

> we can see:
> 
> 1. there is a "sleep" in the parent process, parent works slower than child.
> 
> 2. calling "write" block the child process successfully when pipe is full 
> (4096 bytes on linux by default). The child process does not exit immediately.
> 
> 3. 10 seconds later after child process exist, we can still read messages 
> from the parent process.
> 
> This is exactly the right behavior of inter-processes communication.
> 
> Since we can't add a sleep in grep, tail, less, more, cut..... and we don't 
> know how long should we sleep either.
> 
> How can we prevent message dropping when we are using ch_read ?

I can reproduce it with popen in python:
--------------
parent.py
--------------
import sys, os, time

fp = os.popen('python child.py', 'r')

while 1:
    text = fp.readline()
    if text == '':
        break
    print text.rstrip()
    sys.stdout.flush()
    time.sleep(0.001)

------------
child.py
------------
#! /usr/bin/env python2
import sys, time

t = time.time()
for i in xrange(20000):
    sys.stdout.write('timer job: this is line %d\n'%(i))
    sys.stdout.flush()

t = time.time() - t
print '[done in %d seconds]'%int(t)

# as channel.txt said, we need a sleep here
time.sleep(1)

----------------
reproduce
----------------
$ python parent.py
timer job: this is line 0
timer job: this is line 1
timer job: this is line 2
.....
timer job: this is line 19996
timer job: this is line 19997
timer job: this is line 19998
timer job: this is line 19999
[done in 21 seconds]

-------------
1. there is a sleep in parent.py, parent works slower than child too.
2. the child.py can be blocked successfully by parent.py
3. no sleep in child.py
4. no message dropped.

it behaves the same way just like the c version in my previous post.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui