in reply to running a loop in background...

The MisterHouse Perl-based X-10 home automation inverts this problem. Rather than running a loop in the background, they service Tk in the foreground loop. If I recall correctly, they use the 4 argument form of select(), which might induce a bit of typing lag.

The MisterHouse code base is fascinating (and occassionally horrifying) to spend time in. Within one big outer loop, it services X10, Tk, a Web Server, and a bunch of statically and dynamically scheduled tasks.