how to read and write data with pyserial at same time

How can i make pyserial read and write at same time or at same program? Right now i only know how to either write or to read but not both simultaneiously. So how can i do it? I tried this simple code:

int incomingByte = 0;

void setup() {

Serial.begin(9600); // opens serial port, sets data rate to 9600 bps


void loop() {

incomingByte =; // read the incoming byte:

Serial.print(" I received:");



and python program is:

import serial
ser = serial.Serial('/dev/ttyACM0',9600)
data = ser.readline()
print data


Have a look at this Python - Arduino demo