<div dir="ltr"><div class="markdown-here-wrapper" style><p style="margin:1.2em 0px!important">I think you need to pass <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline;background-color:rgb(248,248,248)">sys.argv</code> to <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline;background-color:rgb(248,248,248)">QApplication</code></p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-python" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">import</span> sys
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">from</span> PyQt5.Qt <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">import</span> QApplication, QMainWindow
app = QApplication(sys.argv)
w = QMainWindow()
w.show()
app.exec_()
</code></pre>
<div title="MDH:SSB0aGluayB5b3UgbmVlZCB0byBwYXNzIGBzeXMuYXJndmAgdG8gYFFBcHBsaWNhdGlvbmA8ZGl2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TogMTNweDsiPncu
c2hvdygpPC9zcGFuPjxiciBzdHlsZT0iZm9udC1mYW1pbHk6IGFyaWFsLCBzYW5zLXNlcmlmOyBm
b250LXNpemU6IDEzcHg7Ij48c3BhbiBzdHlsZT0iZm9udC1mYW1pbHk6IGFyaWFsLCBzYW5zLXNl
cmlmOyBmb250LXNpemU6IDEzcHg7Ij5hcHAuZXhlY18oKTwvc3Bhbj48YnI+PC9kaXY+PGRpdj5g
YGA8L2Rpdj4=" style="height:0;font-size:0em;padding:0;margin:0"></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 9 October 2014 12:28, Kovid Goyal <span dir="ltr"><<a href="mailto:kovid@kovidgoyal.net" target="_blank">kovid@kovidgoyal.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've recently started getting a seemingly random crash on program<br>
termination on linux x64. It can be reproduced with this script:<br>
<br>
from PyQt5.Qt import QApplication, QMainWindow<br>
<br>
app = QApplication([])<br>
<br>
w = QMainWindow()<br>
w.show()<br>
app.exec_()<br>
<br>
<br>
Running it with python2 causes a segfault about once in 20 executions.<br>
Unfortunately, there is stack corruption so the backtrace is not very<br>
useful. And the crash does not occur running under gdb.<br>
<br>
#0 0x00007f0ab58d5069 in ?? ()<br>
#1 0x00007f0ab3bb0f10 in ?? ()<br>
#2 0x00000000018c8920 in ?? ()<br>
#3 0x00007f0ab3bb0f50 in ?? ()<br>
#4 0x00000000018c8c80 in ?? ()<br>
#5 0x00007f0ab3bb1700 in ?? ()<br>
#6 0x00007f0acd8b03be in QThreadPrivate::start (arg=0x18c8920) at thread/qthread_unix.cpp:345<br>
Backtrace stopped: previous frame inner to this frame (corrupt stack?)<br>
<br>
I can however avoid the crash by adding<br>
<br>
del w<br>
del app<br>
<br>
to the end of the script. In other words explicitly deleting the<br>
QMainWindow before the QApplication prevents the crash. As I understand<br>
it this should not be necessary as qapplication.sip should be<br>
transferring ownership of top level widgets to C++ in the QApplication<br>
destructor, and indeed, sip.ispyowned() indicates that ownership is<br>
transferred in the QApplication destructor, so there is something else<br>
going on here. It might just be a timing issue that the explicit<br>
deletion avoids.<br>
<br>
This is with Qt 5.3.2 and PyQt 5.3.2. In the above back trace there is a<br>
reference to the start method of QThreadPrivate. Looking through the Qt<br>
source code I can find no reason for a thread being started during<br>
application shutdown. The xcb QPA plugin does start a thread to talk to<br>
the X server, but that is during startup.<br>
<br>
Obviously, for this simple script the fix is to delete the QMainWindow<br>
before QApplication. However doing that in a more complex application is<br>
not always possible (the best I can think of is to save the main window as an<br>
attribute of the application object). That should ensure that main<br>
window is either deleted before the application or not at all because of<br>
a reference cycle. But I would like to have a proper fix for this, since<br>
if it is a timing issue then this fix may not be robust.<br>
<span class="HOEnZb"><font color="#888888"><br>
Kovid.<br>
<br>
--<br>
_____________________________________<br>
<br>
Dr. Kovid Goyal<br>
<a href="http://www.kovidgoyal.net" target="_blank">http://www.kovidgoyal.net</a><br>
<a href="http://calibre-ebook.com" target="_blank">http://calibre-ebook.com</a><br>
_____________________________________<br>
</font></span><br>_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><font size="1"><b>Marcus Ottosson</b><br><a href="mailto:konstruktion@gmail.com" target="_blank">konstruktion@gmail.com</a></font><font size="1"><br></font></div>
</div>