You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

_master.py 2.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  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. # ============================================================================
  15. """method of server supplied for master"""
  16. import threading
  17. from functools import wraps
  18. from mindspore_serving._mindspore_serving import Master_
  19. _wait_and_clear_thread = None
  20. # waiting for Ctrl+C, and clear
  21. def _start_wait_and_clear():
  22. def thread_func():
  23. print("Serving master: wait for Ctrl+C to exit ------------------------------------")
  24. Master_.wait_and_clear()
  25. global _wait_and_clear_thread
  26. if not _wait_and_clear_thread:
  27. _wait_and_clear_thread = threading.Thread(target=thread_func)
  28. _wait_and_clear_thread.start()
  29. def stop():
  30. Master_.stop()
  31. def stop_on_except(func):
  32. @wraps(func)
  33. def handle_except(*args, **kwargs):
  34. try:
  35. func(*args, **kwargs)
  36. except:
  37. stop()
  38. raise
  39. return handle_except
  40. @stop_on_except
  41. def start_grpc_server(ip="0.0.0.0", grpc_port=5500, max_msg_mb_size=100):
  42. """start grpc server for the communication between client and serving.
  43. the ip should be accessible to the client."""
  44. Master_.start_grpc_server(ip, grpc_port, max_msg_mb_size)
  45. _start_wait_and_clear()
  46. @stop_on_except
  47. def start_master_server(ip="0.0.0.0", grpc_port=6100):
  48. """start grpc server for the communication between workers and the master.
  49. the ip is expected to be accessed only by workers."""
  50. Master_.start_grpc_master_server(ip, grpc_port)
  51. @stop_on_except
  52. def start_restful_server(ip="0.0.0.0", restful_port=5900, max_msg_mb_size=100):
  53. """start restful server for the communication between client and serving.
  54. the ip should be accessible to the client."""
  55. Master_.start_restful_server(ip, restful_port, max_msg_mb_size)
  56. _start_wait_and_clear()

A lightweight and high-performance service module that helps MindSpore developers efficiently deploy online inference services in the production environment.