Edit:
The patch below doesn’t seem to handle KeyboardInterrupts. Nevermind my old post.
Old post:
There’s a timeout option for DataLoader on the master branch, but you’ll have to install master from source 7 until PyTorch updates the binaries.

  
      github.com/pytorch/pytorch
  
  
      
    
  


  Signal handling in DataLoader workers; Timeout option 12



  by SsnL
  on 09:32PM - 03 Nov 17



  10 commits
  changed 4 files
  with 336 additions
  and 18 deletions.


  
  
    
    
  
  



  
      github.com
  
  
    pytorch/pytorch/blob/master/torch/utils/data/dataloader.py#L351 5

    num_workers (int, optional): how many subprocesses to use for data
        loading. 0 means that the data will be loaded in the main process.
        (default: 0)
    collate_fn (callable, optional): merges a list of samples to form a mini-batch.
    pin_memory (bool, optional): If ``True``, the data loader will copy tensors
        into CUDA pinned memory before returning them.
    drop_last (bool, optional): set to ``True`` to drop the last incomplete batch,
        if the dataset size is not divisible by the batch size. If ``False`` and
        the size of dataset is not divisible by the batch size, then the last batch
        will be smaller. (default: False)
    timeout (numeric, optional): if positive, the timeout value for collecting a batch
        from workers. Should always be non-negative. (default: 0)
    worker_init_fn (callable, optional): If not None, this will be called on each
        worker subprocess with the worker id as input, after seeding and before data
        loading. (default: None)


.. note:: By default, each worker will have its PyTorch seed set to
          ``base_seed + worker_id``, where ``base_seed`` is a long generated
          by main process using its RNG. You may use ``torch.initial_seed()`` to access
          this value in :attr:`worker_init_fn`, which can be used to set other seeds
          (e.g. NumPy) before data loading.