-
Notifications
You must be signed in to change notification settings - Fork 21
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
Allow multithreading via config #86
Comments
In v0.4.0 I stored an open database connection on each In v0.4.1 (released yesterday) I changed it so the open connection is stored by the Let me know how it goes with v0.4.1 |
Sad to report that the same issue persists in the new version too. It's due to me initializing Wordnet in another thread and then calling operations in it. But I don't know a better way to implement this as of yet. |
I see, too bad. I'm not very familiar with the threading API (although I have used multiprocessing and subprocess), so can you please provide a minimal example that illustrates the problem? That will help me with debugging. |
As a quick example, this code doesn't work with wn 0.4.1 for me: #!/usr/bin/python3
import os
import threading
import wn
from wn import Wordnet
class wordnet_thread_demo:
wn_instance = None
def __init__(self):
wn_thread = threading.Thread(target=self.set_wn_instance)
wn_thread.start()
wn_thread.join()
print(self.wn_instance.synsets("word"))
def set_wn_instance(self):
if self.wn_instance is None:
self.wn_instance = Wordnet(lexicon="ewn:2020")
wordnet_thread_demo() |
Great, thanks, I was able to reproduce the issue. Also we might try setting |
I think that might work for me. Just checking, doesn't wn.download() always create a separate db connection from when we create an instance of wn.Wordnet ? Because that's the only time any form of writing would be done in my application. |
That might have been the case in v0.4.0, but from v0.4.1 one database connection is made per database location. Basically, there is only one connection, unless you do something, then reassign Writing isn't exactly a problem with the multithreading, it's just that the onus is on the caller to prevent multiple threads from writing to the database at the same time. If you only have one thread that is writing, there shouldn't be any conflicts. |
Ah, I see. Thanks for clearing that up! Sounds good to me. |
Renaming the issue and adding the 'enhancement' label as this is now a feature request for some config option that enables the |
This is now resolved in v0.5.0. See the |
Thank you! I'll check it out! |
Ever since wn 0.4.0 , my application has been unable to use wn with the following error:
Full traceback:
Any pointers as to how to work around this would be much appreciated.
Edit: What I mean is, the same thread check should probably be disabled for read operations unless I'm missing something.
The text was updated successfully, but these errors were encountered: