code: def _test_every_event_filter_with_engine_with_dataloader(device):
      def _test(num_workers):
          max_epochs = 3
          batch_size = 4
          num_iters = 21
          data = torch.randint(0, 1000, size=(num_iters * batch_size,))
  
          dataloader = torch.utils.data.DataLoader(
              data,
              batch_size=batch_size,
              num_workers=num_workers,
              pin_memory="cuda" in torch.device(device).type,
              drop_last=True,
              shuffle=True,
          )
          seen_batchs = []
  
          def update_fn(_, batch):
              batch_to_device = batch.to(device)
              seen_batchs.append(batch)
  
          engine = Engine(update_fn)
  
          def foo(_):
              pass
  
          engine.add_event_handler(Events.EPOCH_STARTED(every=2), foo)
          engine.run(dataloader, max_epochs=max_epochs)
          engine = None
  
          import gc
  
          gc.collect()
          assert len(gc.garbage) == 0
  
      _test(num_workers=0)
      _test(num_workers=1)
  
imports: from enum import Enum
  from unittest.mock import MagicMock
  import pytest
  import torch
  import ignite.distributed
  from ignite.engine import Engine, Events
  from ignite.engine.events import CallableEventWithFilter, EventEnum, EventsList
label_desc: Use image node_id 21 for calling a global function with example usage: _test_every_event_filter_with_engine_with_dataloader(device) without return types