def test_inmem_batched_dataloader_exit_without_hang(synthetic_dataset, reader_factory):
    """
    See if InMemBatchedDataLoader would cause hang if not iterating.
    """
    for _ in range(5):
        with reader_factory(synthetic_dataset.url, schema_fields=['^id$']) as reader:
            with InMemBatchedDataLoader(reader) as _:
                assert reader.stopped

    See if InMemBatchedDataLoader would cause hang if not iterating.
    
petastorm/tests/test_pytorch_dataloader.py