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
Python generated file compiled with Cython causes error with protobuf 3.2.0 #2896
Comments
I added some trace to
Here is what it looks like when
I also forced One option of course is to turn off this check, as is already done for PyPy. An argument in favor of this is that the docs for |
If this check can't be implemented with Cython, feel free to disable it for that environment. I'm not aware of anyone using protobuf with Cython! Will be interested to hear more about how well it works (or doesn't) on this issue. |
I'm not Cythoning the protobuf library, only the generated user _pb2.py files. This means there can't be a static check (something like The pure-Python versions of Protobuf seem to work fine with Cython, and as I mentioned in my second comment a brief check suggests the C++-based version works fine too. I can't tell you if it works any better i.e. faster because we're not really Cythoning it for that... We just have some _pb2 files as part of larger packages where other modules definitely do benefit from Cython, and it would be a huge administrative pain to run Cython on some modules and not others (essentially I think we'd have to separate them out in to separate packages). I expect the fancy descriptor stuff that generated pb2s use are quite opaque to Cython, and even if they used normal Python methods instead they'd probably also need some static type hints (i.e. cdefs) to get much benefit. |
Just for reference, the issue where Linux wheels were enabled is #2623 (but don't get me wrong, it's great that they are). |
Prevents running into following issue: protocolbuffers/protobuf#2896
Pure python does not do the check because it "is somewhat difficult to implement correctly in PyPy". I don't think we have enough reasons to disable it in cpp implementation only for Cython. arthur-tacca, have your checked the issue if it is raised by the strcmp against "_pb2.py" at the end of this function? If so, Your other suggestion make sense to me: |
@anandolee Yes that fixes it for me. Although the change is tiny I don't think I can make a pull request because I'm not sure I can sign the CLI. I could test if someone else is prepared to make a pull request? Perhaps @BigQuant who opened #4231? |
I can make a PR. Will be great if you can help test and review |
Just a note / learning. After seeing the same message in our code.
The problem was that the file was named |
When a _pb2 is compiled with Cython, and the C++ backend of the Python library is turned on (as it now is on Linux for the PyPI deployed protobuf, as of 3.2.0), instantiating any message object gives an error. I am using Python 3.5. Here's an example of the error:
The immediate cause of the error is
_CheckCalledFromGeneratedFile
ingoogle/protobuf/pyext/message.cc
, which calls_CalledFromGeneratedFile
ingoogle/protobuf/pyext/descriptor.cc
. I haven't looked any further than this, but my suspicion is raised by thestrcmp
against"_pb2.py"
at the end of this function. I think that for Cython the filename would end with"_pb2.c"
, but I'm not sure.Just to be completely explicit, here are steps to reproduce:
Then run:
python setup.py build_ext --inplace
The text was updated successfully, but these errors were encountered: