From: Robert Klemme Date: 2008-08-08T02:03:17+09:00 Subject: Re: Threaded IO trouble On 07.08.2008 15:27, Michal Suchanek wrote: > On 07/08/2008, Michal Suchanek wrote: >> On 07/08/2008, Robert Klemme wrote: >> > 2008/8/7 Michal Suchanek : >> > >> > > On 07/08/2008, Robert Klemme wrote: >> > >> >> > >> And it misses another line at the beginning: >> > >> >> > >> $defout.sync = true >> > >> >> > >> :-) >> > > >> > > Fixing the mockup is not the right way, >> > >> > >> > Maybe I am missing your point but the buffering in the mock client is >> > certainly delaying the complete process. Also, I did not only add >> > that line to mock.rb but provided a different client implementation. >> > Did you actually try it out? >> >> >> Sorry, I did not try that yet. >> > > Well, I did not quite understand how your client maps to my client, > and it is indeed completely different. > > While your client does only one popen my client does numerous popens. > This is necessary to work around the buffering: the pipe is closed > every time so that the application knows it's time to print out the > rest of the output. Well, that obviously depends on the application you are using for filtering. If it will send out the last output only on termination there is no other way than to create new processes over and over again. Of course, this is not really efficient - especially for short lived processes - no matter what programming language you use. > Your client is indeed very slow with the mockup and might fail > completely with the application I use. I am not sure what you mean by "slow". I hope you noticed the sleep in there. > I haven't explored the option of using an EOF marker instead of > closing the pipe too much. Maybe that would be the option that works > around limitations in both my application and Ruby. So the application that replaces mock.rb is under your control? I was assuming that it is not and you need to work with it as is. In that case you should certainly introduce some kind of signaling for the end of one chunk of data (if that is needed). > As for duplication the IO using a fd: I was unsure it is safe to use a > single IO structure in two threads. It is because you are using it in one direction in each thread only. Cheers robert