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

Creating GF fails if done from a separate thread #555

Closed
semjon00 opened this issue Jul 3, 2024 · 2 comments · Fixed by #558
Closed

Creating GF fails if done from a separate thread #555

semjon00 opened this issue Jul 3, 2024 · 2 comments · Fixed by #558
Labels
bug Something isn't working

Comments

@semjon00
Copy link

semjon00 commented Jul 3, 2024

Hello! Thank you for this nice library! Here is a bug report:

Currently, the databases are accessed using a singleton cursor. Due to the way the cursor is created, the database disallows accessing it from a thread that does not match the thread in which it was created. This may cause the creation of fields to fail if they are created from different threads.

Here is a code that reproduces the issue:

from threading import Thread
from galois import GF

if __name__ == '__main__':
    field = GF(7)

    t = Thread(target=lambda: GF(11), args=())
    t.start()
    t.join()

A possible fix would be to substitute the
cls.conn = sqlite3.connect(cls.file)
with
cls.conn = sqlite3.connect(cls.file, check_same_thread=False)
inside the constructor of galois._databases._interface.DatabaseInterface.
I believe that this is a safe thing to do, since there are no write operations to the database.

@mhostetter mhostetter added the bug Something isn't working label Jul 3, 2024
@mhostetter
Copy link
Owner

Thanks for the report. This looks good to me. If you'd like to submit a PR, we can get it merged. Otherwise, I can apply the patch.

@semjon00
Copy link
Author

semjon00 commented Jul 4, 2024

It turns out there are more issues that could arise due to using multiple threads.

@mhostetter mhostetter linked a pull request Jul 5, 2024 that will close this issue
@semjon00 semjon00 closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants