_MultiProcessingDataLoaderIter error in torch dataloader

aniketmaurya: <p>Hi, while training a model with torch dataloader I am getting this error.</p>
<pre><code class="lang-auto">Exception ignored in: &lt;function _MultiProcessingDataLoaderIter.__del__ at 0x7f3e3a495320&gt;
Traceback (most recent call last):
  File "/home/coviamai/miniconda3/envs/aniket/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1324, in __del__
    self._shutdown_workers()
  File "/home/coviamai/miniconda3/envs/aniket/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1264, in _shutdown_workers
    if not self._shutdown:
AttributeError: '_MultiProcessingDataLoaderIter' object has no attribute '_shutdown'
Exception ignored in: &lt;function _MultiProcessingDataLoaderIter.__del__ at 0x7f3e3a495320&gt;
Traceback (most recent call last):
  File "/home/coviamai/miniconda3/envs/aniket/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1324, in __del__
    self._shutdown_workers()
  File "/home/coviamai/miniconda3/envs/aniket/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1264, in _shutdown_workers
    if not self._shutdown:
AttributeError: '_MultiProcessingDataLoaderIter' object has no attribute '_shutdown'
</code></pre>

ptrblck: <p>I’m not sure why <code>self._shutdown</code> is not recognized most likely in <a href="https://github.com/pytorch/pytorch/blob/3c3bba4169067a7340ff1d786a6b61282cf26820/torch/utils/data/dataloader.py#L1268">this line of code</a> as it’s defined <a href="https://github.com/pytorch/pytorch/blob/3c3bba4169067a7340ff1d786a6b61282cf26820/torch/utils/data/dataloader.py#L893">here</a>. Are you running into a previous exception or does the stack trace show more errors?</p>

msailor: <p>I am getting the same exception quite regularly.</p>
<p>The stack trace was the same for me as in the original post. To try to get a better idea of what is going on, I inserted a breakpoint before <a href="https://github.com/pytorch/pytorch/blob/8d365ae9402179399e49090f1523bf33bea6ba3a/torch/utils/data/dataloader.py#L1289" rel="noopener nofollow ugc"><code>if not self._shutdown</code></a> if there was no <code>_shutdown</code> attribute. When I print out a stack trace at this breakpoint, however, it seems to vary randomly. For example, here are the last few lines of the stack trace the last two times I ran my code:</p>
<pre><code class="lang-auto">  /opt/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/connection.py(928)wait()
-&gt; with _WaitSelector() as selector:
  /opt/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/selectors.py(349)__init__()
-&gt; super().__init__()
  /Users/malcolm/venvs/ms_ml_utils2/lib/python3.9/site-packages/torch/utils/data/dataloader.py(1361)__del__()
-&gt; self._shutdown_workers()
&gt; /Users/malcolm/venvs/ms_ml_utils2/lib/python3.9/site-packages/torch/utils/data/dataloader.py(1292)_shutdown_workers()
-&gt; if not self._shutdown:
</code></pre>
<pre><code class="lang-auto">  /opt/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/queues.py(190)_start_thread()
-&gt; self._close = Finalize(
  /opt/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/util.py(199)__init__()
-&gt; self._kwargs = kwargs or {}
  /Users/malcolm/venvs/ms_ml_utils2/lib/python3.9/site-packages/torch/utils/data/dataloader.py(1361)__del__()
-&gt; self._shutdown_workers()
&gt; /Users/malcolm/venvs/ms_ml_utils2/lib/python3.9/site-packages/torch/utils/data/dataloader.py(1292)_shutdown_workers()
-&gt; if not self._shutdown:
</code></pre>
<p>Since <a href="https://github.com/pytorch/pytorch/blob/8d365ae9402179399e49090f1523bf33bea6ba3a/torch/utils/data/dataloader.py#L902" rel="noopener nofollow ugc"><code>_shutdown</code> is defined in <code>__init__()</code></a> of the <code>_MultiProcessingDataLoaderIter</code> class, I tried inserting <code>self._shutdown = False</code> on the very first line of the init function, just to see what would happen. Doing this didn’t seem to make any difference—<code>__init__</code> doesn’t seem to be invoked before the call to <code>__del__</code>.</p>
<p>I presume there is something not quite right about my dataloader but I’m having trouble working out what it is!</p>

Flavius_Biras: <p>Got the same exact issue now, and have no idea why __shutdown is not recognized. Do you happen to remember how you solved these?</p>