in reply to Tk and blocking loops

If you are able to poll your input channel to see whether there's any data waiting before attempting to read it (as you can with serial input), you might consider doing so in a repeat callback. I've done this using a string as a queue, appending new data to the end, and processing (and deleting) syntactic chunks as they appear. (Regexes are great for recognizing and extracting such chunks.)

When such polling is not possible, you can use fileevent, but I might think twice about trying to handle the data every time it triggers a callback. Better just to enqueue it and get out. Then use a repeat callback to recognize, dequeue, and process the data at a controllable rate. That way you won't be trying to process every individual byte as it comes in at the risk of slowing GUI response to a crawl.