<s> import os <EOL> from teena import Error <EOL> from teena . thread_loop import ThreadLoop <EOL> def test_thread_loop_runs_in_background ( ) : <EOL> read_fd , write_fd = os . pipe ( ) <EOL> strings = [ ] <EOL> def process_input ( fd , events ) : <EOL> while True : <EOL> try : <EOL> data = os . read ( fd , <NUM_LIT> ) <EOL> except ( Error . EAGAIN , Error . EINTR ) : <EOL> continue <EOL> except ( Error . EPIPE , Error . ECONNRESET , Error . EIO ) : <EOL> loop . stop ( ) <EOL> return <EOL> break <EOL> if not data : <EOL> loop . stop ( ) <EOL> strings . append ( data ) <EOL> loop = ThreadLoop ( ) <EOL> loop . add_handler ( read_fd , process_input , loop . READ ) <EOL> with loop . background ( ) : <EOL> os . write ( write_fd , "<STR_LIT>" ) <EOL> os . write ( write_fd , "<STR_LIT>" ) <EOL> os . close ( write_fd ) <EOL> assert '<STR_LIT>' . join ( strings ) == "<STR_LIT>" <EOL> os . close ( read_fd ) </s>
