Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

69 строки
2.8KB

  1. import os
  2. import sys
  3. from flask.cli import pass_script_info, get_debug_flag, run_command
  4. import click
  5. @click.command()
  6. @click.option('--host', '-h', default='127.0.0.1',
  7. help='The interface to bind to.')
  8. @click.option('--port', '-p', default=5000,
  9. help='The port to bind to.')
  10. @click.option('--reload/--no-reload', default=None,
  11. help='Enable or disable the reloader. By default the reloader '
  12. 'is active if debug is enabled.')
  13. @click.option('--debugger/--no-debugger', default=None,
  14. help='Enable or disable the debugger. By default the debugger '
  15. 'is active if debug is enabled.')
  16. @click.option('--eager-loading/--lazy-loader', default=None,
  17. help='Enable or disable eager loading. By default eager '
  18. 'loading is enabled if the reloader is disabled.')
  19. @click.option('--with-threads/--without-threads', is_flag=True,
  20. help='These options are only supported for compatibility with '
  21. 'the original Flask local development server and are ignored.')
  22. @pass_script_info
  23. def run(info, host, port, reload, debugger, eager_loading, with_threads):
  24. """Runs a local development server for the Flask-SocketIO application.
  25. The reloader and debugger are by default enabled if the debug flag of
  26. Flask is enabled and disabled otherwise.
  27. """
  28. debug = get_debug_flag()
  29. if reload is None:
  30. reload = bool(debug)
  31. if debugger is None:
  32. debugger = bool(debug)
  33. if eager_loading is None:
  34. eager_loading = not reload
  35. # Extra startup messages. This depends a bit on Werkzeug internals to
  36. # not double execute when the reloader kicks in.
  37. if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
  38. # If we have an import path we can print it out now which can help
  39. # people understand what's being served. If we do not have an
  40. # import path because the app was loaded through a callback then
  41. # we won't print anything.
  42. if info.app_import_path is not None:
  43. print(' * Serving Flask-SocketIO app "%s"' % info.app_import_path)
  44. if debug is not None:
  45. print(' * Forcing debug mode %s' % (debug and 'on' or 'off'))
  46. def run_server():
  47. app = info.load_app()
  48. if 'socketio' not in app.extensions:
  49. # flask-socketio is installed, but it isn't in this application
  50. # so we invoke Flask's original run command
  51. run_index = sys.argv.index('run')
  52. sys.argv = sys.argv[run_index:]
  53. return run_command()
  54. socketio = app.extensions['socketio']
  55. socketio.run(app, host=host, port=port, debug=debugger,
  56. use_reloader=False, log_output=debugger)
  57. if reload:
  58. from werkzeug.serving import run_with_reloader
  59. run_with_reloader(run_server)
  60. else:
  61. run_server()