-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Milestone
Description
The basic problem is that MonetDBe-Python does not allow multiple concurrent connections. It uses class level state in the class Frontend (_active_context) to ensure that. The first thread that connects, gets a connection which is closed by the second thread that connects.
I think that this is a remnant from the time we assumed only one connection at a time in a MonetDBe process.
But this can now be relaxed. Take a look at this MonetDBe native example for how this can be done with pthreads.
When this is fixed, I expect something like the following Python code to work:
import monetdbe
import concurrent.futures
monet_conn_1 = monetdbe.connect("devdb", autocommit=True)
monet_conn_1.execute("CREATE TABLE foo (i INT);")
def write_table():
monet_conn_2 = monetdbe.connect("devdb", autocommit=True)
n = 0
while n < 10:
print("write_table")
monet_conn_2.execute("INSERT INTO foo VALUES (10);")
n=n+1
def read_table():
monet_conn_3 = monetdbe.connect("devdb", autocommit=True)
n = 0
while n < 10:
print("read_table")
monet_conn_3.cursor().execute("SELECT * FROM foo;")
print(len(monet_conn_3.cursor().fetchall()))
n=n+1
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.submit(write_table)
executor.submit(read_table)
Metadata
Metadata
Assignees
Labels
No labels