WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-30-2016, 03:22 AM
VizMars VizMars is offline
Member
 
Join Date: Jan 2016
Posts: 40
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)
Reply With Quote
  #2  
Old 02-03-2016, 03:01 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You would have to return the value from the director function to a task to get it back in the main thread:
Reply With Quote
Reply

Tags
database, thread

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending a value by Thread Alex Miranda Vizard 0 11-19-2014 06:52 AM
Access the vertices of a model pankaj bansal Vizard 1 03-29-2013 07:02 PM
Access to Geometry Data in a c++ plugin for vizard. xabbu Plug-in development 1 01-16-2009 03:14 PM
Prioritize Director thread aznan Vizard 9 05-14-2008 09:57 AM
running into a thread limit tavaksai Vizard 4 10-27-2004 03:59 PM


All times are GMT -7. The time now is 01:43 AM.


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