<div dir="ltr">We had intermittent crashing last year in our pyqt 5.2 app (60k LOC back then, 100k now), about 50% of time the app would freeze when doing stuff in the graphics view or when exiting. It was not database related, but the following methodology might still be helpful: <div><br></div><div>We ended up tackling this problem by creating a script that could run our PyQt app repeatedly and calculate how often it crashed (1%, 10%, 50%?) or froze on exit or ran to completion, and to gradually remove code from our pyqt app without affecting these crash stats. When there was about 100 lines of code left in the app (!) and we could still observe the crashing, we were able to identify two lines of code which, if changed a certain way, eliminated the crashes. </div><div><br></div><div>There was no obvious problem with the lines of code, they seemed legit, and each line seemed unrelated to the other (they were in different sections of the app; example: the crash % went to zero if we remove the style of the widget embedded in the graphics view, or emitted only builtin data with a signal, and nothing in this signal data or signal itself was involved in anything that needed to use the style!). But at least we could then try a couple different work-arounds and determine if the crash % went to 0 without having to give up the funcitonality we were using with those 2 lines of code, functionality that was used all over the app. </div><div><br></div><div>It was painful, took days. Given the code involved, it was almost certainly a Qt or PyQt bug, but we didn't have the tools to investigate at the C++ level so finding a "blind" workaround (without having an understanding of the cause) was the only option. After we applied the work-around everywhere in the full app, the crashes stopped (btw, every place in the code where workaround was applied decreased the crash incidence a bit!). The crashes would only come back when a developer added code that used the "normal" approach rather than the workaround, and whenever we noticed this and did a search and fixed it, sure enough the crash % went to 0.  </div><div><br></div><div>HTH, </div><div>Oliver</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, 7 Oct 2016 at 16:57 Pradip Dattani <<a href="mailto:pradip.dattani@ntlworld.com">pradip.dattani@ntlworld.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-GB" link="blue" vlink="purple" class="gmail_msg"><div class="m_1497422106828406974WordSection1 gmail_msg"><p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d" class="gmail_msg">Thanks Oliver.<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p><p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d" class="gmail_msg">No, not in a thread. There are no additional threads created in this application.  <u class="gmail_msg"></u><u class="gmail_msg"></u></span></p><p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d" class="gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></span></p><p class="MsoNormal gmail_msg"><b class="gmail_msg"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="gmail_msg">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif" class="gmail_msg"> oliver [mailto:<a href="mailto:oliver.schoenborn@gmail.com" class="gmail_msg" target="_blank">oliver.schoenborn@gmail.com</a>] <br class="gmail_msg"><b class="gmail_msg">Sent:</b> Friday, October 7, 2016 9:55 PM<br class="gmail_msg"><b class="gmail_msg">To:</b> Pradip Dattani <<a href="mailto:pradip.dattani@ntlworld.com" class="gmail_msg" target="_blank">pradip.dattani@ntlworld.com</a>>; <a href="mailto:pyqt@riverbankcomputing.com" class="gmail_msg" target="_blank">pyqt@riverbankcomputing.com</a><br class="gmail_msg"><b class="gmail_msg">Subject:</b> Re: [PyQt] ODBC error while accessing SQL Server from PyQt application<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p></div></div><div lang="EN-GB" link="blue" vlink="purple" class="gmail_msg"><div class="m_1497422106828406974WordSection1 gmail_msg"><p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p><p class="gmail_msg">Is the query executed in GUI thread? <u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p><div class="gmail_msg"><div class="gmail_msg"><p class="MsoNormal gmail_msg">On Fri, Oct 7, 2016, 16:23 Pradip Dattani <<a href="mailto:pradip.dattani@ntlworld.com" class="gmail_msg" target="_blank">pradip.dattani@ntlworld.com</a>> wrote:<u class="gmail_msg"></u><u class="gmail_msg"></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><p class="MsoNormal gmail_msg">We have written our first PyQt (4.6) application. However we have hit a serious road block due to an intermittent database access error.<u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg"> <u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg">The error we see is:  <b class="gmail_msg">“[Microsoft][ODBC Driver Manager] Invalid string or buffer length”.</b><u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg"> <u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg">The application has a number of Tableviews,  drop down lists, TreeWidget etc. Most of these are populated dynamically by querying the database.<u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg">Database queries are made through custom API code that uses SqlAlchemy. We do not use QtSql module.<u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg"> <u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg">We see this error only when executing a database query from within PyQt application. It’s very random and therefore not a reproducible error. Has anyone seen this before and got any pointers to resolve such issues. We have tried to google. We see many posts but no answers. <u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg"> <u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg">Are there any good practices we should observe when querying database from within PyQt application.<u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg"> <u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg">Thank you in advance. <u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg">Regards,<u class="gmail_msg"></u><u class="gmail_msg"></u></p><p class="MsoNormal gmail_msg">Pradip<u class="gmail_msg"></u><u class="gmail_msg"></u></p></div></div><p class="MsoNormal gmail_msg">_______________________________________________<br class="gmail_msg">PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com" class="gmail_msg" target="_blank">PyQt@riverbankcomputing.com</a><br class="gmail_msg"><a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" class="gmail_msg" target="_blank">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><u class="gmail_msg"></u><u class="gmail_msg"></u></p></blockquote></div><div class="gmail_msg"><p class="MsoNormal gmail_msg">-- <u class="gmail_msg"></u><u class="gmail_msg"></u></p></div><div class="gmail_msg"><div class="gmail_msg"><p class="MsoNormal gmail_msg">Oliver<u class="gmail_msg"></u><u class="gmail_msg"></u></p></div></div></div></div></blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">Oliver</div></div>