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

Add multithreading compatibility #558

Merged
merged 1 commit into from
Jul 5, 2024
Merged

Add multithreading compatibility #558

merged 1 commit into from
Jul 5, 2024

Conversation

semjon00
Copy link

@semjon00 semjon00 commented Jul 5, 2024

#555

I changed three things:
(1) as before, check_same_thread=False to sqlite3.connect
(2) used a lock for cursor actions to prevent the situation where a query is made before the result for another query is read
(3) used the same lock for instance creation, since two threads could race and create two connections (which is unintended).
An alternative approach is to somehow create a connection per thread, then the locks won't be necessary

This approach sadly introduces an import from threading. I hope it is ok, this module should be present in all supported interpreters.

@mhostetter mhostetter changed the base branch from main to release/0.4.x July 5, 2024 15:37
@mhostetter
Copy link
Owner

Thanks for the PR! This looks good to me.

For some reason I thought we needed singleton = None in each subclass or else they'd share the same class variable. That doesn't appear to be the case (your changes are working).

And, like you say, I think threading should always be available, so I'm fine with adding it. If people complain because they don't have it on some interpreters, I may consider removing it.

@mhostetter mhostetter merged commit 5bf5c79 into mhostetter:release/0.4.x Jul 5, 2024
49 checks passed
@mhostetter mhostetter linked an issue Jul 5, 2024 that may be closed by this pull request
@semjon00
Copy link
Author

semjon00 commented Jul 5, 2024

Thank you for reviewing and merging!

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

Successfully merging this pull request may close these issues.

Creating GF fails if done from a separate thread
2 participants