__main__.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  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. import os
  15. import sys
  16. from .paddlex_cli import main
  17. def console_entry() -> int:
  18. # See https://docs.python.org/3/library/signal.html#note-on-sigpipe
  19. try:
  20. # Flush output here to force SIGPIPE to be triggered while inside this
  21. # try block.
  22. code = main()
  23. sys.stdout.flush()
  24. sys.stderr.flush()
  25. return code
  26. except BrokenPipeError:
  27. # Python flushes standard streams on exit;
  28. # redirect remaining output to devnull to avoid another BrokenPipeError
  29. # at shutdown.
  30. devnull = os.open(os.devnull, os.O_WRONLY)
  31. os.dup2(devnull, sys.stdout.fileno())
  32. return 1
  33. if __name__ == "__main__":
  34. sys.exit(console_entry())