MCPcopy Create free account
hub / github.com/PAIR-code/lit / serve

Method serve

lit_nlp/dev_server.py:79–116  ·  view source on GitHub ↗

Run server, with optional reload loop and cache saving. If the server type is 'external', then the app is returned instead of served by this module. Returns: WSGI app if the server type is 'external', server if the server type is 'notebook', otherwise None when serving is c

(self)

Source from the content-addressed store, hash-verified

77 self._server_type = server_type
78
79 def serve(self) -> Optional[LitServerType]:
80 """Run server, with optional reload loop and cache saving.
81
82 If the server type is 'external', then the app is returned instead of
83 served by this module.
84
85 Returns:
86 WSGI app if the server type is 'external', server if the server type
87 is 'notebook', otherwise None when serving is complete.
88 """
89
90 logging.info(termcolor.colored(get_lit_logo(), 'red', attrs=['bold']))
91 logging.info(
92 termcolor.colored('Starting LIT server...', 'green', attrs=['bold'])
93 )
94 app = lit_app.LitApp(*self._app_args, **self._app_kw)
95
96 # If using a separate server program to serve the app, such as gunicorn,
97 # then just return the WSGI app instead of serving it directly.
98 if self._server_type == 'external':
99 return app
100 # Pre-bake mode runs any warm-start functions, saves the cache,
101 # and exits. Designed to be used in container setup for faster launching.
102 if self._server_type == 'prebake':
103 app.save_cache()
104 logging.info('Pre-bake completed; exiting server.')
105 return
106
107 server_fn = WSGI_SERVERS[self._server_type]
108 server = server_fn(app, **self._server_kw)
109
110 # server.serve isn't blocking for notebook server type.
111 # For other types, the underlying server registers a SIGINT handler,
112 # so if you hit Ctrl+C it will return.
113 server.serve()
114 if self._server_type == 'notebook':
115 return server
116 app.save_cache()

Callers 8

__init__Method · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95

Calls 3

save_cacheMethod · 0.95
get_lit_logoFunction · 0.85
infoMethod · 0.80

Tested by

no test coverage detected