def chunk_action(iterable, action, wait_action=None, ignore_func=None, batch_size=<NUM_LIT:100>):
batch = list()<EOL>def process_batch():<EOL><INDENT>batch_len = len(batch)<EOL>result = action(batch)<EOL>if wait_action:<EOL><INDENT>wait_action(result)<EOL><DEDENT>del batch[:]<EOL>return batch_len<EOL><DEDENT>count = <NUM_LIT:0><EOL>for n, item in enumerate(iterable, start=<NUM_LIT:1>):<EOL><INDENT>if n % batch_size == <NUM_LIT:0>:<EOL><INDENT>if ignore_func and not ignore_func(item):<EOL><INDENT>batch.append(item)<EOL><DEDENT>count += process_batch()<EOL><DEDENT>else:<EOL><INDENT>batch.append(item)<EOL><DEDENT><DEDENT>if batch:<EOL><INDENT>count += process_batch()<EOL><DEDENT>return count<EOL>
Ensure action is executed on chunks not greater than batch_size elements.
If the callable wait_action is not None, it will be passed the results of
executing action.