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
The library is not thread-safe #106
Comments
I imagine you can fix this for your application by calling |
Yes, I fixed exactly in this way. But the bug exists in the library anyway. |
This bug has been open a while and I am keen to fix it. Before I roll up my sleeves and do some research on the best approach, I'd invite anyone who is more familiar with an appropriate idiomatic approach to contribute a patch to resolve it. My aim would be to preserve lazy loading the UTS46 data until needed, if possible. |
There must be something non-obvious going on here, or a bug in Python itself or in libc on @socketpair's machine, because Python already uses a lock around imports - originally global, preventing all concurrent imports, and since 3.3 on a per-module basis:
https://docs.python.org/3.3/whatsnew/3.3.html#a-finer-grained-import-lock So the original bug report "cannot happen". If it is a bug in Python then it could be worked around by adding a manual lock around the _import_lock = threading.Lock()
def uts46_remap(domain: str, std3_rules: bool = True, transitional: bool = False) -> str:
"""Re-map the characters in the string according to UTS46 processing."""
with _import_lock:
from .uts46data import uts46data
output = ''
... |
I had Python 3.9, as you can see. Possibly it's a bug. But I don't know where. Can you reproduce ? it's possible to suspend importing by inserting time.sleep() at the root scope of a file. |
I've not been able to reproduce this issue, so for now I am going to close this issue. If it can be reproduced happy to reopen. |
This happens beacause
uts46_remap()
importsfrom .uts46data import uts46data
inside. When this happens in two threads in parallel, it leads to error above. Really hard to trigger, but it happens sometimes.The text was updated successfully, but these errors were encountered: