PySerial API thinks the com port is still open during a write(), why?
Question: I am using PySerial (a Python API for serial communication) to send AT
commands to a Nokia phone via bluetooth.

    
    
    import serial
    com = serial.Serial()
    com.port = 19
    com.timeout = 0 #also tried a timeout value greater than 0.
    try:
        com.open()
        # at this point I turn off the phone.
        com.write("AT\r\n")
        print com.readlines()
    except SerialException, e:
        print e
    

Just after I open() the com, I turn off the phone. Then, I write("AT\r\n"). At
this point, the function blocks and the runtime hangs.

Do you have any solution?


Answer: With a timeout set to `0`, you desactivate the timeout parameter, the
`read()/readlines()` becomes a blocking call. The caller will be blocked until
the device answers. Try to set a non-zero timeout value to your serial
connection `com = serial.Serial(timeout=0.5)`.

If it still hangs, the problem should be in the bluetooth stack.

