Python SQLite スレッド間でコネクションの使いまわしは出来ない
以下のエラーが出た。
ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 5052 and this is thread id 3176
SQLiteのオブジェクトは作成されたスレッドでしか使えない。とのこと。
そういうもんなのか。。。ちょっと面倒。
■ サンプルプログラム
ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 5052 and this is thread id 3176
SQLiteのオブジェクトは作成されたスレッドでしか使えない。とのこと。
そういうもんなのか。。。ちょっと面倒。
■ サンプルプログラム
import sqlite3
class CreateConnection(threading.Thread):
connection = sqlite3.connect(':memory:')
def __init__(self):
threading.Thread.__init__(self)
def run(self):
sql = 'SELECT col1 from TEST_TABLE'
self.connection.cursor().execute(sql)
if __name__ == '__main__':
sql = "CREATE TABLE TEST_TABLE ( col1 INTEGER );"
sqlite3.connect(':memory:').cursor().execute(sql)
CreateConnection().start()
コメント
コメントを投稿