The Mangy Yak

Monday, July 10, 2006

Need RMA for my Brain

Today I spent 6 hours fighting a bug.
I think my brain has a defect. I was observing a weird behavior where some remote processes seemed to be dying earlier than they should. This only happened under I/O-intensive processes. All kinds of conjectures went through my head - from the simplest to the most complicated. I will spare you from the details.

Anyway, I was almost giving up when, all of a sudden, I saw this piece of code (blogger sucks for posting code, so cut me some slack on this):

while(true){

try{
...
}catch(){
...
}catch(){
...
}finally{

try {

if (closeOnExit)

lReader.close();

} catch (IOException ex) {

logger.error("Failed to close output stream.", ex);

}

}

}

}

This loop forwards the streams to the remote server. It only iterates when the buffer overflows, and the buffer only overflows if the flush timeout is small enough or if the process writes enough stuff to STDOUT/STDERR. So, I was essentially closing the stream on the first iteration, causing the underlying process to die earlier than I was expecting it to.

Damn. My tests weren't getting this because I use very large buffers (up to 2000 characters), and my toy test processes didn't produce that much output. When I attempted to dump the old testament on-screen (my favourite for stress tests), this odd behavior appeared.

Oh well. At least I'm getting somewhere.

Thursday, July 06, 2006

Uncool, unproductive day today. I've been mulling over Teaching Assistant issues for two days, and looks like tomorrow won't be any different. I guess I won't be delivering that milestone I promissed after all. :-(

Hope I can deliver the others on schedule.

Tuesday, July 04, 2006

From Tcl/Tk to Python



The whitespace madness with my Expect Tcl/Tk script was getting unbearable. Oh, wait, you don't know what the whitespace madness was. Basically, it is very difficult to propagate parameters containing whitespaces to a remote program that is called from SSH when you already call SSH from another script. You have to get the script to 'double quote' the arguments, and I was just not being able to do this with Expect Tcl/Tk. It kept adding curly braces {} to my quoted arguments, making them unusable.

Admittedly this was due to sheer incompetence since I'm not very acquainted with Expect nor Tcl/Tk, but I had to get things working somehow.
After scavenging poorly-organized documentation and reading articles for half a day, I decided to put an end to this - I don't have the time to become a skilled Expect Tcl/Tk programmer right now.

So I tried Pexpect, a simplified Expect for Python. Well, it worked great! In fact, Python is great.

Took me a while to get my code working, though, since my Python is kind of rusty. You can feel sorry for me by taking a look at the code I wrote. It's there for everyone to see, in my CVS.

See ya!