cygrpc.pyx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright 2015 gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # distutils: language=c++
  15. cimport cpython
  16. import logging
  17. import os
  18. import sys
  19. import threading
  20. import time
  21. import grpc
  22. try:
  23. import asyncio
  24. except ImportError:
  25. # TODO(https://github.com/grpc/grpc/issues/19728) Improve how Aio Cython is
  26. # distributed without breaking none compatible Python versions. For now, if
  27. # Asyncio package is not available we just skip it.
  28. pass
  29. # The only copy of Python logger for the Cython extension
  30. _LOGGER = logging.getLogger(__name__)
  31. # TODO(atash): figure out why the coverage tool gets confused about the Cython
  32. # coverage plugin when the following files don't have a '.pxi' suffix.
  33. include "_cygrpc/grpc_string.pyx.pxi"
  34. include "_cygrpc/arguments.pyx.pxi"
  35. include "_cygrpc/call.pyx.pxi"
  36. include "_cygrpc/channel.pyx.pxi"
  37. include "_cygrpc/channelz.pyx.pxi"
  38. include "_cygrpc/csds.pyx.pxi"
  39. include "_cygrpc/credentials.pyx.pxi"
  40. include "_cygrpc/completion_queue.pyx.pxi"
  41. include "_cygrpc/event.pyx.pxi"
  42. include "_cygrpc/metadata.pyx.pxi"
  43. include "_cygrpc/operation.pyx.pxi"
  44. include "_cygrpc/propagation_bits.pyx.pxi"
  45. include "_cygrpc/records.pyx.pxi"
  46. include "_cygrpc/security.pyx.pxi"
  47. include "_cygrpc/server.pyx.pxi"
  48. include "_cygrpc/tag.pyx.pxi"
  49. include "_cygrpc/time.pyx.pxi"
  50. include "_cygrpc/vtable.pyx.pxi"
  51. include "_cygrpc/_hooks.pyx.pxi"
  52. include "_cygrpc/grpc_gevent.pyx.pxi"
  53. include "_cygrpc/thread.pyx.pxi"
  54. IF UNAME_SYSNAME == "Windows":
  55. include "_cygrpc/fork_windows.pyx.pxi"
  56. ELSE:
  57. include "_cygrpc/fork_posix.pyx.pxi"
  58. # Following pxi files are part of the Aio module
  59. include "_cygrpc/aio/common.pyx.pxi"
  60. include "_cygrpc/aio/rpc_status.pyx.pxi"
  61. include "_cygrpc/aio/completion_queue.pyx.pxi"
  62. include "_cygrpc/aio/callback_common.pyx.pxi"
  63. include "_cygrpc/aio/grpc_aio.pyx.pxi"
  64. include "_cygrpc/aio/call.pyx.pxi"
  65. include "_cygrpc/aio/channel.pyx.pxi"
  66. include "_cygrpc/aio/server.pyx.pxi"
  67. #
  68. # initialize gRPC
  69. #
  70. cdef extern from "Python.h":
  71. int PyEval_InitThreads()
  72. cdef _initialize():
  73. # We have Python callbacks called by c-core threads, this ensures the GIL
  74. # is initialized.
  75. PyEval_InitThreads()
  76. import ssl
  77. grpc_dont_init_openssl()
  78. # Load Arcadia certs in ComputePemRootCerts and do not override here.
  79. _initialize()