Start a server instance. This method blocks until the server terminates. :param app: WSGI application or target string supported by :func:`load_app`. (default: :func:`default_app`) :param server: Server adapter to use. See :data:`server_names` keys for
(app=None,
server='wsgiref',
host='127.0.0.1',
port=8080,
interval=1,
reloader=False,
quiet=False,
plugins=None,
debug=None,
config=None, **kargs)
| 4021 | |
| 4022 | |
| 4023 | def run(app=None, |
| 4024 | server='wsgiref', |
| 4025 | host='127.0.0.1', |
| 4026 | port=8080, |
| 4027 | interval=1, |
| 4028 | reloader=False, |
| 4029 | quiet=False, |
| 4030 | plugins=None, |
| 4031 | debug=None, |
| 4032 | config=None, **kargs): |
| 4033 | """ Start a server instance. This method blocks until the server terminates. |
| 4034 | |
| 4035 | :param app: WSGI application or target string supported by |
| 4036 | :func:`load_app`. (default: :func:`default_app`) |
| 4037 | :param server: Server adapter to use. See :data:`server_names` keys |
| 4038 | for valid names or pass a :class:`ServerAdapter` subclass. |
| 4039 | (default: `wsgiref`) |
| 4040 | :param host: Server address to bind to. Pass ``0.0.0.0`` to listens on |
| 4041 | all interfaces including the external one. (default: 127.0.0.1) |
| 4042 | :param port: Server port to bind to. Values below 1024 require root |
| 4043 | privileges. (default: 8080) |
| 4044 | :param reloader: Start auto-reloading server? (default: False) |
| 4045 | :param interval: Auto-reloader interval in seconds (default: 1) |
| 4046 | :param quiet: Suppress output to stdout and stderr? (default: False) |
| 4047 | :param options: Options passed to the server adapter. |
| 4048 | """ |
| 4049 | if NORUN: return |
| 4050 | if reloader and not os.environ.get('BOTTLE_CHILD'): |
| 4051 | import subprocess |
| 4052 | fd, lockfile = tempfile.mkstemp(prefix='bottle.', suffix='.lock') |
| 4053 | environ = os.environ.copy() |
| 4054 | environ['BOTTLE_CHILD'] = 'true' |
| 4055 | environ['BOTTLE_LOCKFILE'] = lockfile |
| 4056 | args = [sys.executable] + sys.argv |
| 4057 | # If a package was loaded with `python -m`, then `sys.argv` needs to be |
| 4058 | # restored to the original value, or imports might break. See #1336 |
| 4059 | if getattr(sys.modules.get('__main__'), '__package__', None): |
| 4060 | args[1:1] = ["-m", sys.modules['__main__'].__package__] |
| 4061 | |
| 4062 | try: |
| 4063 | os.close(fd) # We never write to this file |
| 4064 | while os.path.exists(lockfile): |
| 4065 | p = subprocess.Popen(args, env=environ) |
| 4066 | while p.poll() is None: |
| 4067 | os.utime(lockfile, None) # Tell child we are still alive |
| 4068 | time.sleep(interval) |
| 4069 | if p.returncode == 3: # Child wants to be restarted |
| 4070 | continue |
| 4071 | sys.exit(p.returncode) |
| 4072 | except KeyboardInterrupt: |
| 4073 | pass |
| 4074 | finally: |
| 4075 | if os.path.exists(lockfile): |
| 4076 | os.unlink(lockfile) |
| 4077 | return |
| 4078 | |
| 4079 | try: |
| 4080 | if debug is not None: _debug(debug) |