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, **kargs)
| 2304 | NORUN = nr_old |
| 2305 | |
| 2306 | def run(app=None, server='wsgiref', host='127.0.0.1', port=8080, |
| 2307 | interval=1, reloader=False, quiet=False, plugins=None, **kargs): |
| 2308 | """ Start a server instance. This method blocks until the server terminates. |
| 2309 | |
| 2310 | :param app: WSGI application or target string supported by |
| 2311 | :func:`load_app`. (default: :func:`default_app`) |
| 2312 | :param server: Server adapter to use. See :data:`server_names` keys |
| 2313 | for valid names or pass a :class:`ServerAdapter` subclass. |
| 2314 | (default: `wsgiref`) |
| 2315 | :param host: Server address to bind to. Pass ``0.0.0.0`` to listens on |
| 2316 | all interfaces including the external one. (default: 127.0.0.1) |
| 2317 | :param port: Server port to bind to. Values below 1024 require root |
| 2318 | privileges. (default: 8080) |
| 2319 | :param reloader: Start auto-reloading server? (default: False) |
| 2320 | :param interval: Auto-reloader interval in seconds (default: 1) |
| 2321 | :param quiet: Suppress output to stdout and stderr? (default: False) |
| 2322 | :param options: Options passed to the server adapter. |
| 2323 | """ |
| 2324 | if NORUN: return |
| 2325 | if reloader and not os.environ.get('BOTTLE_CHILD'): |
| 2326 | try: |
| 2327 | fd, lockfile = tempfile.mkstemp(prefix='bottle.', suffix='.lock') |
| 2328 | os.close(fd) # We only need this file to exist. We never write to it |
| 2329 | while os.path.exists(lockfile): |
| 2330 | args = [sys.executable] + sys.argv |
| 2331 | environ = os.environ.copy() |
| 2332 | environ['BOTTLE_CHILD'] = 'true' |
| 2333 | environ['BOTTLE_LOCKFILE'] = lockfile |
| 2334 | p = subprocess.Popen(args, env=environ) |
| 2335 | while p.poll() is None: # Busy wait... |
| 2336 | os.utime(lockfile, None) # I am alive! |
| 2337 | time.sleep(interval) |
| 2338 | if p.poll() != 3: |
| 2339 | if os.path.exists(lockfile): os.unlink(lockfile) |
| 2340 | sys.exit(p.poll()) |
| 2341 | except KeyboardInterrupt: |
| 2342 | pass |
| 2343 | finally: |
| 2344 | if os.path.exists(lockfile): |
| 2345 | os.unlink(lockfile) |
| 2346 | return |
| 2347 | |
| 2348 | stderr = sys.stderr.write |
| 2349 | |
| 2350 | try: |
| 2351 | app = app or default_app() |
| 2352 | if isinstance(app, basestring): |
| 2353 | app = load_app(app) |
| 2354 | if not callable(app): |
| 2355 | raise ValueError("Application is not callable: %r" % app) |
| 2356 | |
| 2357 | for plugin in plugins or []: |
| 2358 | app.install(plugin) |
| 2359 | |
| 2360 | if server in server_names: |
| 2361 | server = server_names.get(server) |
| 2362 | if isinstance(server, basestring): |
| 2363 | server = load(server) |
no test coverage detected