If you don’t terminate the program, you could just get the data from the dataloader using dat = next(dl) (python 3 syntax) instead of a for loop.
If you do have separate programs it might be more straightforward to introduce a stable splitting of the dataset or something like that (it probably is also good for reproducibility).
Best regards
Thomas