WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Access database in (non-main) thread (https://forum.worldviz.com/showthread.php?t=5622)

VizMars 01-30-2016 03:22 AM

Access database in (non-main) thread
 
Hi,

when I execute my code (simplified code stated below) I get this error:
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 6596 and this is thread id 5748

But when I'm running the exact same code in Vizards main thread it works just fine. So what am I doing wrong or do I have to use another way to store data in a database from a separate (non-main) thread?


Code:

        def example():                       
                con = sqlite3.connect("test.db")
               
                con.execute("""
                        CREATE TABLE tbl_01(
                        test TEXT)
                """)               
               
                def onKeyDown(key):               
                        if key == viz.KEY_UP:                               
                                con.execute("""
                                        INSERT INTO tbl_01
                                        VALUES(?)
                                """, "t")
       
                                con.commit()
                               
                viz.callback(viz.KEYDOWN_EVENT,onKeyDown)
       
        viz.director(example)


Jeff 02-03-2016 03:01 PM

You would have to return the value from the director function to a task to get it back in the main thread:


All times are GMT -7. The time now is 03:23 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC