I am using QGIS 2.18.21 and PostgreSQL 9.6. on a Windows 8 machine.
I am trying to do processing of a certain database task in the background, and I want the user to be able to continue to work in the meantime. The threaded class looks like:
class LoadCanvasStagingData(QThread):
def __init__(self, username, transaction_id, connection_string):
QThread.__init__(self)
self.username = username
self.transaction_id = transaction_id
self.selected_database = selected_database
self.connection_string = connection_string
def run(self):
# print ('\n\rsleeping')
# time.sleep(0.05)
# print ('done sleeping')
con = psycopg2.connect(connection_string)
cur = con.cursor()
query = """ SELECT
*
FROM qgis_validation_plugin.fetch_transaction(
'{0}'::CHARACTER VARYING,
ARRAY[{1}]::BIGINT[]
);
""".format(self.username, self.transaction_id)
cur.execute(query)
cur.close()
con.commit()
con.close()
It is called with:
loadCanvasStagingData = LoadCanvasStagingData(self, self.username, self.transaction_id, self.connection_string)
loadCanvasStagingData.finished.connect(self.refreshCanvas)
loadCanvasStagingData.start()
It crashes on load about 75% of the times (with a .dmp file generation), seemingly unrelated to the data. But it does not crash at all if I uncomment the time.sleep.
Also, if I move the sleep thread to the bottom, it also does not seem to crash.
Does anyone know what might be going on?
Could it be that it has something to do with the implementation of thread.wait thread.quit in that implementation?
– Lennert De Feyter Jul 23 '18 at 14:32I suspect it is due to thread safety between a dialog box and the canvas. But I cannot be sure.
– Lennert De Feyter Aug 02 '18 at 11:06