def test_combined_loader_simultaneous_workers(mode):
    """Test `CombinedLoader` to check how it initializes dataloader workers."""

    class TestDataLoader(DataLoader):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.workers_active = False

        def _get_iterator(self):
            self.workers_active = True
            return super()._get_iterator()

        def _shutdown_workers(self):
            self.workers_active = False
            super()._shutdown_workers()

    loaders = [
        TestDataLoader(range(10), batch_size=2, num_workers=0),
        TestDataLoader(range(20), batch_size=2, num_workers=0),
    ]
    combined_loader = CombinedLoader(loaders, mode)
    # Start the dataloader
    _ = iter(combined_loader)

    workers_active = []
    for loader in loaders:
        workers_active.append(loader.workers_active)

    # Sequential only starts the first dataloader, other modes start both
    expected = [True, False] if mode == "sequential" else [True, True]
    assert workers_active == expected
Test `CombinedLoader` to check how it initializes dataloader workers.
tests/tests_pytorch/utilities/test_combined_loader.py