Readlines implementaiton with timeout handling