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.

debugger_server_base.py 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2021 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. """DebuggerServerBase."""
  16. import threading
  17. from abc import abstractmethod
  18. from functools import wraps
  19. from mindinsight.debugger.common.exceptions.exceptions import DebuggerServerRunningError
  20. from mindinsight.debugger.common.log import LOGGER as log
  21. def debugger_server_wrap(func):
  22. """Wrapper for catch exception."""
  23. @wraps(func)
  24. def record_log(*args, **kwargs):
  25. try:
  26. return func(*args, **kwargs)
  27. except Exception as err:
  28. log.exception(err)
  29. raise DebuggerServerRunningError(str(err))
  30. return record_log
  31. class DebuggerServerBase(threading.Thread):
  32. """
  33. Debugger Server Base.
  34. Args:
  35. cache_store (DebuggerCacheStore): Cache store for debugger server.
  36. context (DebuggerServerContext): Context for initialize debugger server.
  37. """
  38. def __init__(self, cache_store, context):
  39. super(DebuggerServerBase, self).__init__()
  40. self._cache_store = cache_store
  41. self._context = context
  42. @abstractmethod
  43. @debugger_server_wrap
  44. def run(self):
  45. """Function that should be called when thread started."""
  46. @abstractmethod
  47. @debugger_server_wrap
  48. def stop(self):
  49. """Stop debugger server."""