__main__.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import os
  16. import sys
  17. from .paddlex_cli import main
  18. def console_entry() -> int:
  19. # See https://docs.python.org/3/library/signal.html#note-on-sigpipe
  20. try:
  21. # Flush output here to force SIGPIPE to be triggered while inside this
  22. # try block.
  23. code = main()
  24. sys.stdout.flush()
  25. sys.stderr.flush()
  26. return code
  27. except BrokenPipeError:
  28. # Python flushes standard streams on exit;
  29. # redirect remaining output to devnull to avoid another BrokenPipeError
  30. # at shutdown.
  31. devnull = os.open(os.devnull, os.O_WRONLY)
  32. os.dup2(devnull, sys.stdout.fileno())
  33. return 1
  34. if __name__ == "__main__":
  35. sys.exit(console_entry())