Pytorch code can't stop

username: Chengming_Zhang
cooked: <p>As long as the code of pytorch is designed to differentiate automatically and calls backward() function, it will cause the program cannot automatically stop, and the key of stop square will become a skeleton. Who can tell me how to solve it? It drives me crazy! The current torch version is 1.3.0. And the IDE I used is pycharm.</p>

username: albanD
cooked: <p>Hi,</p>
<p>This is because pytorch uses c++ code to speed up computations and PyCharm cannot interrupt it while it’s in the c++ code. This is a good sign actually, that means that your code spend most of its time in c++ and is thus very efficient <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: Chengming_Zhang
cooked: <p>Actually I need to use matlab to call the script written by pytorch, so I expect the python script can stop automatically after running. Do you know how to fix this bug? Thank you very much!!!</p>

username: albanD
cooked: <p>Hi,</p>
<p>I am not sure to understand what you mean by “cannot stop autatically” ?</p>
<p>Also which OS are you using?</p>

username: Chengming_Zhang
cooked: <p>Hello,<br>
My Os is window 7. I hope the three figures could explain my confusion. As is show in fig 1, “Process finished with exit code 0”. Just after I execute the backward(), I find the code can’t terminate, although code has finished! (fig 2). And the code can be run perfectly in python console(fig 3). So how to terminate automatically even if I call the backward() function. That’ the point! Again, thanks a lot for your time. It really very kind of you!!!</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/0/207ab3ac5ca65dacee156810b8e213b7d075e8fd.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/207ab3ac5ca65dacee156810b8e213b7d075e8fd" title="figure"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/0/207ab3ac5ca65dacee156810b8e213b7d075e8fd_2_667x500.jpeg" alt="figure" data-base62-sha1="4DkakeezUXIeyj4BnOvw0ITqVZP" width="667" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/0/207ab3ac5ca65dacee156810b8e213b7d075e8fd_2_667x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/2/0/207ab3ac5ca65dacee156810b8e213b7d075e8fd_2_1000x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/2/0/207ab3ac5ca65dacee156810b8e213b7d075e8fd_2_1334x1000.jpeg 2x" data-dominant-color="48494A"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">figure</span><span class="informations">2048×1534 466 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: albanD
cooked: <p>Hi,</p>
<p>This may be linked to <a href="https://github.com/pytorch/pytorch/issues/29383" rel="nofollow noopener">https://github.com/pytorch/pytorch/issues/29383</a> as well.<br>
I am not sure what to do here as we cannot reproduce this.<br>
Could you give more informations on how you installed pytorch, and which version you use? Do you use cuda?</p>

username: Chengming_Zhang
cooked: <p>hi,<br>
I installed pytorch on Windows 7 using conda ( <code>conda install pytorch torchvision cpuonly -c pytorch </code> ) in the most recent, stable version (python 3.7, pytorch 1.3.0). And I ever used pytorch 1.2.0, the issue still exited.</p>

username: peterjc123
cooked: <p>This issue is only reproducible on Windows 7 currently. However, we don’t have Windows 7 machines for debugging. So to make it clear, you’ll need to build the debug version of PyTorch, get the stacktrace in the  C++ side and then we may know what’s wrong there.</p>