taking indefinite time

I was following this tutorial to train on CIFAR10 dataset. Everything works fine but is taking indefinite time.

The dataset is already present in the folder. I am using 4.19.88-1-MANJARO with Python3.6 and PyTorch v1.3.1. I don’t have any GPU related libraries installed.

Also, does it loads the whole data into memory when trainloader is initialized or it picks in batches at the step?

import torch
import torchvision
import torchvision.transforms as transforms

transform = transforms.Compose(
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]

trainset = torchvision.datasets.CIFAR10(root='../data', train=True,
                                        download=False, transform=transform)
trainloader =, batch_size=2,
                                          shuffle=True, num_workers=4)

testset = torchvision.datasets.CIFAR10(root='../data', train=False,
                                       download=False, transform=transform)
testloader =, batch_size=4,
                                         shuffle=False, num_workers=2)

classes = ('plane', 'car', 'bird', 'cat',
           'deer', 'dog', 'frog', 'horse', 'ship', 'truck')

import matplotlib.pyplot as plt
import numpy as np

def imshow(img):
    img = img / 2 + 0.5     # unnormalize
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0)))

# get some random training images
dataiter = iter(trainloader)
images, labels =   <-- taking indefinite time

Could you try to set num_workers=0 in your DataLoader and check, if you get a valid batch?

Yes, it worked. Thank you very much. I am new to PyTorch. Could you please explain me what happened?

This was just a debugging step to narrow down the potential root cause of the issue.
It seems that mutliprocessing causes the hang. I’m not familiar with Manjaro, but could you check the amount of shared memory on your system?