Solved by ptrblck in post #2 
              
              
                Is your code working in a terminal? 
Are you using multiple workers in your DataLoader? 
If so, could you add the “if-clause protection” as described here.