Why is there a problem with the code execution order of python when you connect a python script to a port with nc?

this is the content of test.py:

< H1 >! / usr/bin/python < / H1 >

print "hello"
a=raw_input ()
print a

now I execute. / test.py
in the linux terminal. I will first print the hello, and then prompt me for input, and finally print the input result, as shown below, no problem:

hello
1
1

but if I hang this test.py under a port:
socat tcp-l:9992,fork exec:./test.py
then nc this port on another local terminal:
nc 127.0.0.1 9992

will let me enter a first, and then print the hello, final output a, as follows:
1
hello
1

this is obviously not in line with the expected execution order, where is the reason, please answer, thank you!

Aug.02,2021

you obviously don't know what input is and what is output.

in the first case, the output is sent to the output pipe immediately.

hello // 
1  // 
1   // 

in the second case, the output is returned to you after all execution.

1  // 
hello // 
1   // 

nc returns all output after the script is executed, so hello does not return first, but with the next 1.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3effd-34824.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3effd-34824.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?