threadings_utils.py 524 B

1234567891011121314151617181920
  1. from configs import dify_config
  2. def apply_gevent_threading_patch():
  3. """
  4. Run threading patch by gevent
  5. to make standard library threading compatible.
  6. Patching should be done as early as possible in the lifecycle of the program.
  7. :return:
  8. """
  9. if not dify_config.DEBUG:
  10. from gevent import monkey # type: ignore
  11. from grpc.experimental import gevent as grpc_gevent # type: ignore
  12. # gevent
  13. monkey.patch_all()
  14. # grpc gevent
  15. grpc_gevent.init_gevent()