def buffer_batch(generator, buffer_size):

    batches = []
    n = 0

    for x in generator:
        batches.append(x)
        n += batch_length(x)

        if n < buffer_size:
            continue

        batch, batches = __split_batches(batches, buffer_size)

        if batch is not None:
            yield batch
            batch = None
            n = 0

    # Run out the remaining samples
    while batches:
        batch, batches = __split_batches(batches, buffer_size)
        if batch is not None:
            yield batch
Test that a lock can be acquired while a lock is held
dataset/ETHPy150Open bmcfee/pescador/pescador/util.py/buffer_batch--crossover with--dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/test/test_defer.py/DeferredFilesystemLockTestCase.test_waitUntilLockedWithTimeoutUnlocked