<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Armando,<div class="">Thank you so much. It looks like your version of the shutdown procedure works both on my Mac and on Linux. It is no longer necessary to explicitly delete the main window and the QApplication instance, as suggested by the stackoverflow post. I think the other key thing is to do this before calling the QApplication quit() method.<div class=""><br class=""></div><div class="">I still don’t understand why the bug is triggered by calling processEvents(), but that’s an academic question now.</div><div class=""><br class=""></div><div class="">Thanks again,</div><div class="">Ray<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On May 25, 2020, at 4:35 PM, Raymond Osborn <<a href="mailto:rayosborn@mac.com" class="">rayosborn@mac.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Armando,<div class="">Good to hear from you. I thought for a while that I had managed to fix it with the following code :</div><div class=""><br class=""></div><div class=""><div class=""> def main(filename=None):</div><div class=""> app = NXConsoleApp()</div><div class=""> app.initialize(filename=filename)</div><div class=""> app.start()</div><div class=""> for w in QApplication.topLevelWindows():</div><div class=""> del w</div><div class=""> del app.window, app.app</div><div class=""> sys.exit(0)</div><div class=""><br class=""></div><div class="">It proved to be a false dawn - the problem started to recur again. I’ll see if your version catches things that mine missed, and let you know.</div><div class=""><br class=""></div><div class="">I have spent a lot of time trying to cover up PyQt5 bugs in the past year. The problem is that I can’t guarantee that my users will have the latest version of PyQt, so even if it is fixed in v5.14, I still have to patch the code. I just have no idea why simply calling processEvents() triggers the bug. If I knew that, perhaps it would give some clue how to work around it.</div><div class=""><br class=""></div><div class="">Ray</div><div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class=""><div class="">On May 25, 2020, at 3:38 PM, V. Armando Sole <<a href="mailto:sole@esrf.fr" class="">sole@esrf.fr</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class=""><div style="font-size: 10pt; font-family: Verdana,Geneva,sans-serif" class=""><p class="">Hi Ray,</p><p class="">I do not know if it will help your case. I was getting rid of some crashes on exit by deleting all widgets that had no parent. For instance, when closing the QMainWindow by doing:</p><p class=""> def closeEvent(self, event):<br class=""> if __name__ == "__main__":<br class=""> app = qt.QApplication.instance()<br class=""> allWidgets = app.allWidgets()<br class=""> for widget in allWidgets:<br class=""> try:<br class=""> # we cannot afford to crash here<br class=""> if id(widget) != id(self):<br class=""> if widget.parent() is None:<br class=""> widget.close()<br class=""> except:<br class=""> _logger.debug("Error closing widget")<br class=""> return qt.QMainWindow.closeEvent(self, event)</p><p class="">Best regards,</p><p class="">Armando</p><p class="">On 25.05.2020 19:48, Raymond Osborn wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0" class=""><!-- html ignored --><!-- head ignored --><!-- meta ignored -->I added a call to QtWidgets.QApplication.instance().processEvents() in order to force adjustResize() to work when switching tabs (that's another story). It succeeded in fixing my resize issue, but now it triggers a segfault when I exit the application. This seemed to be related to the bug described in <a href="https://www.riverbankcomputing.com/static/Docs/PyQt5/gotchas.html#crashes-on-exit" class="">https://www.riverbankcomputing.com/static/Docs/PyQt5/gotchas.html#crashes-on-exit</a>. One fix, suggested by @ekhumoro on stackoverflow (<a href="https://stackoverflow.com/questions/59120337/why-does-pyqt-sometimes-crash-on-exit" class="">https://stackoverflow.com/questions/59120337/why-does-pyqt-sometimes-crash-on-exit</a>) was to delete the main window and the app first, but that doesn't seem to fix it. I am running PyQt 5.12 because that is the last version supported by conda, so I can't test the one-exit fix in v5.13, and my users probably wouldn't have it installed anyway. It happens on Macs and linux.
<div class=""> </div>
<div class="">What I am asking is if there are additional things to try in addition to @ekhumoro's suggestion? Basically he suggests doing something like:</div>
<div class=""> </div>
<div class="">
<pre class="lang-py prettyprinted prettyprint" style="margin-top: 0px; margin-bottom: 1em; padding: 12px 8px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-stretch: inherit; line-height: inherit; font-size: 13px; vertical-align: baseline; box-sizing: inherit; width: auto; max-height: 600px; overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; color: #242729; word-wrap: normal; caret-color: #242729;"><code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; white-space: inherit;" class=""><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--blue-800);">def</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);"> main</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">():</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">
app </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);"> </span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: #2b91af;">QApplication</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">(</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">sys</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">argv</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">)</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">
main_window </span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">=</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);"> </span><span class="typ" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: #2b91af;">MainWindow</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">()</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">
main_window</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">show</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">()</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">
app</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">exec_</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">()</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">
</span><span class="com" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-400);"># ensure correct deletion order</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">
</span><span class="kwd" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--blue-800);">del</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);"> main_window</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);">,</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; box-sizing: inherit; color: var(--black-750);"> app</span></code></pre>
<div class="">Does anyone understand why the crash only occurs if I have calls to processEvents() in the code? It never happens when I remove them.</div>
</div>
<div class=""> </div>
<div class="">Thanks,</div>
<div class="">Ray</div>
<div class=""> </div>
<div class=""> </div>
</blockquote>
</div>
</div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></body></html>