Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent access to MonetDBe embedded database not possible. #123

Open
aris-koning opened this issue Feb 15, 2021 · 0 comments
Open

Concurrent access to MonetDBe embedded database not possible. #123

aris-koning opened this issue Feb 15, 2021 · 0 comments
Milestone

Comments

@aris-koning
Copy link
Contributor

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)
@gijzelaerr gijzelaerr modified the milestones: 0.10, 0.11 Apr 9, 2021
@gijzelaerr gijzelaerr modified the milestones: 0.11, 0.12 Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants