# RuntimeError in PyTorch's reductions.py when using multiprocessing.Queues with multiple threads

**URL:** <https://discuss.pytorch.org/t/runtimeerror-in-pytorchs-reductions-py-when-using-multiprocessing-queues-with-multiple-threads/114246>\
**Category:** Uncategorized\
**Created:** [March 9, 2021, 7:17pm UTC](https://discuss.pytorch.org/t/runtimeerror-in-pytorchs-reductions-py-when-using-multiprocessing-queues-with-multiple-threads/114246 "2021-03-09T19:17:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [March 11, 2021, 9:37am UTC](https://discuss.pytorch.org/t/runtimeerror-in-pytorchs-reductions-py-when-using-multiprocessing-queues-with-multiple-threads/114246/2 "2021-03-11T09:37:20Z")

</div>

I think your explanation is correct and some thread/process manipulates the `dict`, while the loop is still being executed. Here is a minimal code snippet to reproduce this underlying issue:

```python
x = {a: a+10 for a in range(10)}
for key in x:
    print(key, x[key]) # works

for key in x:
    print(key, x[key])
    x[key+100] = key
> RuntimeError: dictionary changed size during iteration

```

Unfortunately, I don’t know enough about your setup and which process could potentially change the `self.items()` `dict`. In any case, you could add debug statements to see when the `self.items()` objects is being manipulated, which might help in isolating the issue.

---

_[View the full topic](https://discuss.pytorch.org/t/runtimeerror-in-pytorchs-reductions-py-when-using-multiprocessing-queues-with-multiple-threads/114246)._
