import select

def fromAtoB(A, B):
    r, w = select.select([A], [B], [])
if not r:
    select.select([A], [], [])
elif not w:
    select.select([], [B], [])
How to correctly relay TCP traffic between sockets?