Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

gunicorn.conf.py 1.5KB

1234567891011121314151617181920212223242526272829303132
  1. import psycogreen.gevent as pscycogreen_gevent # type: ignore
  2. from gevent import events as gevent_events
  3. from grpc.experimental import gevent as grpc_gevent # type: ignore
  4. # NOTE(QuantumGhost): here we cannot use post_fork to patch gRPC, as
  5. # grpc_gevent.init_gevent must be called after patching stdlib.
  6. # Gunicorn calls `post_init` before applying monkey patch.
  7. # Use `post_init` to setup gRPC gevent support would cause deadlock and
  8. # some other weird issues.
  9. #
  10. # ref:
  11. # - https://github.com/grpc/grpc/blob/62533ea13879d6ee95c6fda11ec0826ca822c9dd/src/python/grpcio/grpc/experimental/gevent.py
  12. # - https://github.com/gevent/gevent/issues/2060#issuecomment-3016768668
  13. # - https://github.com/benoitc/gunicorn/blob/master/gunicorn/arbiter.py#L607-L613
  14. def post_patch(event):
  15. # this function is only called for gevent worker.
  16. # from gevent docs (https://www.gevent.org/api/gevent.monkey.html):
  17. # You can also subscribe to the events to provide additional patching beyond what gevent distributes, either for
  18. # additional standard library modules, or for third-party packages. The suggested time to do this patching is in
  19. # the subscriber for gevent.events.GeventDidPatchBuiltinModulesEvent.
  20. if not isinstance(event, gevent_events.GeventDidPatchBuiltinModulesEvent):
  21. return
  22. # grpc gevent
  23. grpc_gevent.init_gevent()
  24. print("gRPC patched with gevent.", flush=True) # noqa: T201
  25. pscycogreen_gevent.patch_psycopg()
  26. print("psycopg2 patched with gevent.", flush=True) # noqa: T201
  27. gevent_events.subscribers.append(post_patch)