<table cellspacing="0" cellpadding="0" border="0"><tr><td valign="top"><p dir="ltr">The Qt library is single threaded. If you try to use it multithreaded, it might work if you have a unique connection, if you ahderevto the single writer. </p>
<p dir="ltr"><a href="https://overview.mail.yahoo.com/mobile/?.src=Android">Sent from Yahoo Mail on Android</a></p>
</td></tr></table>            <div id="_origMsg_">
                <div>
                    <br />
                    <div>
                        <div style="font-size:0.9em">
                            <hr size="1">
                            <b>
                                <span style="font-weight:bold">From:</span>
                            </b>
                            Gelonida N <gelonida@gmail.com>;                            <br>
                            <b>
                                <span style="font-weight:bold">To:</span>
                            </b>
                             <pyqt@riverbankcomputing.com>;                                                                                                     <br>
                            <b>
                                <span style="font-weight:bold">Subject:</span>
                            </b>
                            [PyQt] QSqlTableModel in ReadOnly mode concurrent with sqlite3      writer thread                            <br>
                            <b>
                                <span style="font-weight:bold">Sent:</span>
                            </b>
                            Tue, Mar 11, 2014 5:26:26 PM                            <br>
                        </div>
                            <br>
                            <table cellspacing="0" cellpadding="0" border="0">
                                <tbody>
                                    <tr>
                                        <td valign="top">Hi,<BR><BR>I have an application with two threads.<BR>One thread tries to update an sqlite data base<BR>another thread (the GUI thread) tries to visualize the same sqlite DB.<BR><BR><BR>The thread that populates the data / updates the db is using the sqlite3 <BR>module of python.<BR><BR>The GUI is using QSqlTableModel to visualize the data.<BR><BR><BR>My problem is following:<BR>  Sometimes (quite often) I get following error message from the thread <BR>trying to populate the DB:<BR>> sqlite3.OperationalError: database is locked<BR><BR>As soon as I create the model (whether displaying the related widget or <BR>not) I encounter "the database is locked" error<BR>>         db = QtSql.QSqlDatabase.addDatabase("QSQLITE")<BR>>         db.setDatabaseName("test.sqlite3")<BR>>        
 db.setConnectOptions("QSQLITE_OPEN_READONLY=1")<BR>>         db.open()<BR>>         model = QtSql.QSqlTableModel()<BR>>         model.setTable("test")<BR>>         model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)<BR>>         model.select()<BR> >         self.db = db<BR> >         self.model = model # IF I REMOVE THIS LINE NO LOCKING OCCURS<BR><BR>removing the last line will autodestroy the model and then my other <BR>thread has no issues.<BR><BR><BR>I read a little about sqlite3 and multithreading and came to the <BR>conclusion that things should work as long as one thread only modifes <BR>data and the other ones just reads and as long as every thread uses its <BR>own connection.<BR><BR>Any suggestions of how I can debug / fix my
 problem?<BR><BR><BR><BR><BR>_______________________________________________<BR>PyQt mailing list    <a ymailto="mailto:PyQt@riverbankcomputing.com" href="javascript:return">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></td>
                                    </tr>
                                </tbody>
                            </table>
                    </div>
                </div>
            </div>