[PyQt] ODBC error while accessing SQL Server from PyQt application

oliver oliver.schoenborn at gmail.com
Sat Oct 8 00:27:07 BST 2016


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:

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.

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.

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.

HTH,
Oliver

On Fri, 7 Oct 2016 at 16:57 Pradip Dattani <pradip.dattani at ntlworld.com>
wrote:

> Thanks Oliver.
>
> No, not in a thread. There are no additional threads created in this
> application.
>
>
>
> *From:* oliver [mailto:oliver.schoenborn at gmail.com]
> *Sent:* Friday, October 7, 2016 9:55 PM
> *To:* Pradip Dattani <pradip.dattani at ntlworld.com>;
> pyqt at riverbankcomputing.com
> *Subject:* Re: [PyQt] ODBC error while accessing SQL Server from PyQt
> application
>
>
>
> Is the query executed in GUI thread?
>
>
>
> On Fri, Oct 7, 2016, 16:23 Pradip Dattani <pradip.dattani at ntlworld.com>
> wrote:
>
> We have written our first PyQt (4.6) application. However we have hit a
> serious road block due to an intermittent database access error.
>
>
>
> The error we see is:  *“[Microsoft][ODBC Driver Manager] Invalid string
> or buffer length”.*
>
>
>
> The application has a number of Tableviews,  drop down lists, TreeWidget
> etc. Most of these are populated dynamically by querying the database.
>
> Database queries are made through custom API code that uses SqlAlchemy. We
> do not use QtSql module.
>
>
>
> 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.
>
>
>
> Are there any good practices we should observe when querying database from
> within PyQt application.
>
>
>
> Thank you in advance.
>
> Regards,
>
> Pradip
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
> --
>
> Oliver
>
-- 
Oliver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161007/48168eaa/attachment-0001.html>


More information about the PyQt mailing list