<s> from collections import namedtuple <EOL> from couchdbkit import ChangesStream <EOL> import time <EOL> CouchChange = namedtuple ( '<STR_LIT>' , [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def stream_changes ( db , since , limit ) : <EOL> for change in ChangesStream ( db = db , since = since , limit = limit ) : <EOL> yield CouchChange ( <EOL> id = change [ '<STR_LIT:id>' ] , rev = change [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , deleted = change . get ( '<STR_LIT>' , False ) , <EOL> seq = change . get ( '<STR_LIT>' ) ) <EOL> def stream_changes_forever ( db , since , chunk_size = <NUM_LIT> , notify_caught_up = True ) : <EOL> last_seq = since <EOL> while True : <EOL> changes = stream_changes ( db = db , since = last_seq , limit = chunk_size ) <EOL> i = - <NUM_LIT:1> <EOL> change = None <EOL> for i , change in enumerate ( changes ) : <EOL> yield change <EOL> if i + <NUM_LIT:1> < chunk_size : <EOL> if notify_caught_up : <EOL> yield Ellipsis <EOL> time . sleep ( <NUM_LIT:10> ) <EOL> if change : <EOL> last_seq = change . seq </s>
