-
Notifications
You must be signed in to change notification settings - Fork 277
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
Compatibility issue with gunicorn #482
Comments
I used the sample application from the gunicorn docs and imported spaCy at the top and it worked without issue. Could you give example code to reproduce your issue and clarify what version of spaCy, thinc, and Python you're using? My code:
|
Hi, Note:
Following are the versions. I am using the following two .py files
Here is the code faiss_wsgi.py
faiss_controller.py
usages Updated Error stack trace
|
Thanks for the code sample. It works with Python 3.9 but I was able to reproduce the error with Python 3.6.9, so I guess it's Python version related. We'll take a closer look at this, but you should be able to work around this by upgrading Python if that's an option. |
So what's happening is that when gunicorn loads First, Python 3.6 is a bit different because it has to use the backported context vars from here. So the implementation is not the same as the standard library version in 3.7+. But it should still support type annotations, and in a 3.6 Python shell If it were just that one line at issue we could try removing the type annotation, but the notation is used in several places, so besides being undesirable that's not even an easy fix. I also verified this code works if the gunicorn work class is I'll keep looking at this, but that's what I've found so far. |
Hi @polm any update? Facing the same issue. Any specified |
I spent some time on this but was unable to figure out what was going wrong. While we'd be glad to accept a PR for this, since it only comes up with a certain combination of an external library and Python 3.6 I don't think it's a high priority bug for us, especially with Python 3.6 reaching EOL this month. Thanks for the info on the workaround with gevent. |
We also just encountered the same issue and downgraded gevent to solve it. Hopefully future versions of spacy will take this into consideration, as it seems important when it comes to deployment in production. |
Thanks for the extra report. It's worth noting that Python 3.6 has reached end of life at this point. Where you using 3.6 or an older version? Is upgrading your Python version not an option? |
Yes. That also could be an option, I suggested either upgrading python to 3.7, or downgrading gevent, and my colleague chose to do the 2nd, and it worked. Python 3.9 may be a little too higher for us, if it is required, but if the root cause is python version compatibility, this won't be a real issue any more. |
As noted upthread, this issue only happens in 3.6 (or, presumably, lower versions) because of the use of a backported library. The relevant code is part of the standard Python library in 3.7+, so if you can upgrade to that or higher it should be fine. |
That's good to know and won't be a concern any more. Thanks. |
@lingvisa Hello, I am having the same issue. I tried it with Python3.6.9 and Python3.8.0. Both have the same error. May I ask which version of gervent are you using? |
gevent==1.4 |
I am trying to import spacy from gunicorn with worker gevent and Flask
File "/tf/notebooks/NLP//model_spacy.py", line 1, in
import spacy
File "/usr/local/lib/python3.6/dist-packages/spacy/init.py", line 10, in
from thinc.api import prefer_gpu, require_gpu, require_cpu # noqa: F401
File "/usr/local/lib/python3.6/dist-packages/thinc/api.py", line 2, in
from .initializers import normal_init, uniform_init, glorot_uniform_init, zero_init
File "/usr/local/lib/python3.6/dist-packages/thinc/initializers.py", line 4, in
from .backends import Ops
File "/usr/local/lib/python3.6/dist-packages/thinc/backends/init.py", line 6, in
from .ops import Ops
File "/usr/local/lib/python3.6/dist-packages/thinc/backends/ops.py", line 10, in
from ..util import get_array_module, is_xp_array, to_numpy
File "/usr/local/lib/python3.6/dist-packages/thinc/util.py", line 15, in
DATA_VALIDATION: ContextVar[bool] = ContextVar("DATA_VALIDATION", default=False)
TypeError: 'type' object is not subscriptable
The text was updated successfully, but these errors were encountered: