the raw socket in support of such usage)but it isn' viable in all scenariosespecially for existing or multimode scripts in many casesit may be most straightforward to use manual flush calls in shell-oriented programs whose streams might be linked to other programs through sockets buffering in other contextscommand pipes revisited also keep in mind that buffered streams and deadlock are general issues that go beyond socket wrapper files we explored this topic in as quick reviewthe nonsocket example - does not fully buffer its output when it is connected to terminal (output is only line buffered when run from shell command prompt)but does if connected to something else (including socket or pipeexample - pp \internet\sockets\pipe-unbuff-writer py output line buffered (unbufferedif stdout is terminalbuffered by default for other devicesuse - or sys stdout flush(to avoid delayed output on pipe/socket import timesys for in range( )print(time asctime()sys stdout write('spam\ 'time sleep( print transfers per stream buffering ditto for direct stream file access unles sys stdout reset to other file although text-mode files are required for python ' print in generalthe - flag still works in to suppress full output stream buffering in example - using this flag makes the spawned script' printed output appear every secondsas it is produced not using this flag defers all output for secondsuntil the spawned script exitsunless the spawned script calls sys stdout flush on each iteration example - pp \internet\sockets\pipe-unbuff-reader py no output for seconds unless python - flag used or sys stdout flush(but writer' output appears here every seconds when either option is used import os for line in os popen('python - pipe-unbuff-writer py')print(lineend=''iterator reads lines blocks without -ufollowing is the reader script' outputunlike the socket examplesit spawns the writer automaticallyso we don' need separate windows to test recall from that os popen also accepts buffering argument much like socket makefilebut it does not apply to the spawned program' streamand so would not prevent output buffering in this case :\pp \internet\socketspipe-unbuff-reader py wed apr : : spam wed apr : : spam network scripting