in the terminal windowbecause of such constraintsto avoid blocked statesa separately running gui cannot generally read data directly if its appearance may be delayed for instancein the socketbased scripts of the prior section (example - )the after timer loop allows the gui to poll for data instead of waitingand display it as it arrives because it doesn' wait for the data to show upits gui remains active in between outputs of coursethe real issue here is that the read/write loop in the guistreams utility function used is too simplisticissuing read call within gui is generally prone to blocking there are variety of ways we might try to avoid this updating guis within threads and other nonsolutions one candidate fix is to try to run the redirection loop call in thread--for exampleby changing the launch function in example - as follows (this is from file pipe-gui thread py on the examples distribution)def launch()import _thread _thread start_new_thread(redirectedguishellcmd('python - pipe-nongui py',)but then we would be updating the gui from spawned threadwhichas we've learnedis generally bad idea parallel updates can wreak havoc in guis if factwith this change the gui fails spectacularly--it hangs immediately on the first "go!button press on my windows laptopbecomes unresponsiveand must be forcibly closed this happens before (or perhaps duringthe creation of the new popup scrolled-text window when this example was run on windows xp for the prior edition of this bookit also hung on the first "go!press occasionally and always hung eventually if you pressed the button enough timesthe process had to be forcibly killed direct gui updates in threads are not viable solution alternativelywe could try to use the python select select call (described in to implement polling for data on the input pipeunfortunatelyselect works only on sockets in windows today (it also works on pipes and other file descriptors in unixin other contextsa separately spawned gui might also use signals to inform the nongui program when points of interaction ariseand vice versa (the python signal module and os kill call were introduced in the downside with this approach is that it still requires changes to the non-gui program to handle the signals named pipes (the fifo files introduced in are sometimes an alternative to the socket calls of the original examples - through - but sockets work on standard windows pythonand fifos do not (os mkfifo is not available in windows in python though it is in cygwin pythoneven where they do workwe would still need an after timer loop in the gui to avoid blocking more ways to add guis to non-gui code