mhostetter / galois

A performant NumPy extension for Galois fields and their applications
https://mhostetter.github.io/galois/
MIT License
338 stars 31 forks source link

Add multithreading compatibility #558

Closed semjon00 closed 4 months ago

semjon00 commented 4 months ago

https://github.com/mhostetter/galois/issues/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 commented 4 months ago

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.

semjon00 commented 4 months ago

Thank you for reviewing and merging!