I have this program that defines a function and then calls it, but no matter what I do, the program doesn't execute the function's call. Am I missing something? I already checked with the other questions but I couldn't find anything similar to what I am facing.
baudrate = 115200
port = '/dev/ttyUSB2' 
def serial_data(ser):
    print ser.name # it doesn't print here at all! 
    sys.stdout.flush()
    while True:
        yield ser.readline()
    ser.close()
    for line in serial_data('/dev/ttyUSB2', 115200):
        print "data : " 
        print line
    data = []
ser = serial.Serial(port, baudrate)
serial_data(ser)
The output for this program is
#nothing, it just hangs.
If I remove the infinite loop, the program terminates immediately.
 
    