Created
April 3, 2015 18:57
-
-
Save cancan101/17241bf59841ed96fb8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import threading | |
db = sqlite3.connect(":memory:", check_same_thread=False) | |
CREATE_NON_LINKED_TABLE = 'CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, original, cleaned, UNIQUE(original))' | |
CREATE_LINKED_TABLE = 'CREATE TABLE IF NOT EXISTS %s (id INTEGER PRIMARY KEY AUTOINCREMENT, original, cleaned, study INTEGER, UNIQUE(original, study), FOREIGN KEY(study) REFERENCES studyinstanceuid(id))' | |
db.isolation_level = None | |
db.execute(CREATE_NON_LINKED_TABLE % 'studyinstanceuid') | |
db.execute(CREATE_LINKED_TABLE % 'patientsname') | |
INSERT_OTHER = 'INSERT INTO %s (original, cleaned) VALUES (?, ?)' | |
INSERT_LINKED = 'INSERT INTO %s (original, cleaned, study) VALUES (?, ?, ?)' | |
db.execute(INSERT_OTHER % 'studyinstanceuid', ('original', 'cleaned')) | |
db.execute(INSERT_LINKED % 'patientsname', ('original', 'cleaned', 1)) | |
def foo(): | |
while True: | |
try: | |
db.execute(INSERT_LINKED % 'patientsname', ('original', 'cleaned', 1)) | |
except sqlite3.IntegrityError as ex: | |
pass | |
a = threading.Thread(target=foo) | |
a.start() | |
b = threading.Thread(target=foo) | |
b.start() | |
a.join() | |
b.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment