__main__.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. main()
  23. sys.stdout.flush()
  24. sys.stderr.flush()
  25. except BrokenPipeError:
  26. # Python flushes standard streams on exit;
  27. # redirect remaining output to devnull to avoid another BrokenPipeError
  28. # at shutdown.
  29. devnull = os.open(os.devnull, os.O_WRONLY)
  30. os.dup2(devnull, sys.stdout.fileno())
  31. sys.exit(1)
  32. if __name__ == "__main__":
  33. console_entry()