[ts-gen] redirecting shim output to python script

Paul C paulq2o0 at yahoo.co.uk
Fri May 22 09:10:47 EDT 2009


In the MacOS thread I modified Mikes python test script such that
it apparently stops responding after the first command is sent to the
shim (on my machine anyway). 
 
I've don't know whether this helps with the python 'lock-up' problem
discussed in that thread, but it reminded me of another problem I find
with ruby when trying to communicate with the shim via popen. I post
it in case there is a connection.

In brief: It seems that with the popen approach, the shim always
accepts the first command sent on stdin (i.e line buffered?), but thereafter appears
to want either a complete 4096 characters *or* a delay between commands being sent. 

The following script should result in two 'ping' commands being sent
to the shim, but only the first makes it:

   exec = "/home/paul/z/shim --data cout file"
   shim = IO.popen(exec, "w+");
   shim.sync=true
   sleep 10 #
   
   shim.syswrite "ping line one;\n"
   # sleep 0.01 # commented out - a delay here will resolve the problem
   shim.flush
   shim.syswrite "ping line two;\n" # Doesn't get sent (?)
   shim.flush
   
   #shim.fsync # doesn't seem to work
   #shim.close_write # this would resolve the problem, but we want 
                     # to keep the pipe open so we can write again.
   while line = shim.gets do
     puts line
   end


Using the following loop to send 100 commands to the shim results in
only 65 ping statements appearing in the output, i.e. the first line
and the next 64x64 (=4096==pipe_buffer size?) bytes (?).

   for i in 101..200 do
    shim.syswrite "ping __all_lines_64_characters_long_including_newline______#{i};\n"
    shim.flush
   end

Again, a 'sleep' inbetween syswrite commands will make it work.  As does adding
a setvbuf(stdin,NULL,_IONBF,0) to the shim source code (where it
probably doesn't belong - I add it only for diagnostic reasons.)


Regards
Paul C



More information about the ts-general mailing list