本文整理汇总了Python中bokeh.server.server.Server类的典型用法代码示例。如果您正苦于以下问题:Python Server类的具体用法?Python Server怎么用?Python Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: func
def func(self, args):
if args.port >= 0:
self.port = args.port
self.develop_mode = args.develop
applications = self.build_applications(args)
# TODO make log level a command line option
logging.basicConfig(level=logging.DEBUG)
server = Server(applications, port=self.port, address=args.address)
if args.show:
# we have to defer opening in browser until
# we start up the server
def show_callback():
for route in applications.keys():
server.show(route)
server.io_loop.add_callback(show_callback)
if self.develop_mode:
log.info("Using develop mode (do not enable --develop in production)")
address_string = ''
if server.address is not None and server.address != '':
address_string = ' address ' + server.address
log.info("Starting Bokeh server on port %d%s with applications at paths %r",
server.port,
address_string,
sorted(applications.keys()))
server.start()
示例2: invoke
def invoke(self, args):
'''
'''
# protect this import inside a function so that "bokeh info" can work
# even if Tornado is not installed
from bokeh.server.server import Server
log_level = getattr(logging, args.log_level.upper())
basicConfig(level=log_level, format=args.log_format)
applications = {}
_allowed_keys = ['port', 'address']
server_kwargs = { key: getattr(args, key) for key in _allowed_keys if getattr(args, key, None) is not None }
with report_server_init_errors(**server_kwargs):
server = Server(applications, **server_kwargs)
address_string = ''
if server.address is not None and server.address != '':
address_string = ' address ' + server.address
log.info("Starting Bokeh static server on port %d%s", server.port, address_string)
server.run_until_shutdown()
示例3: invoke
def invoke(self, args):
applications = build_single_handler_applications(args.files)
log_level = getattr(logging, args.log_level.upper())
logging.basicConfig(level=log_level)
if len(applications) == 0:
# create an empty application by default, typically used with output_server
applications['/'] = Application()
server = Server(applications, port=args.port, address=args.address)
if args.show:
# we have to defer opening in browser until we start up the server
def show_callback():
for route in applications.keys():
server.show(route)
server.io_loop.add_callback(show_callback)
if args.develop:
log.info("Using develop mode (do not enable --develop in production)")
address_string = ''
if server.address is not None and server.address != '':
address_string = ' address ' + server.address
log.info("Starting Bokeh server on port %d%s with applications at paths %r",
server.port,
address_string,
sorted(applications.keys()))
server.start()
示例4: BokehServer
class BokehServer(object):
def listen(self, port):
if self.server:
return
for i in range(5):
try:
self.server = Server(self.apps, io_loop=self.loop, port=port,
check_unused_sessions_milliseconds=500,
host=['*'])
self.server.start(start_loop=False)
break
except (SystemExit, EnvironmentError):
port = 0
if i == 4:
raise
@property
def port(self):
return (self.server.port or
list(self.server._http._sockets.values())[0].getsockname()[1])
def stop(self):
for context in self.server._tornado._applications.values():
context.run_unload_hook()
self.server._tornado._stats_job.stop()
self.server._tornado._cleanup_job.stop()
if self.server._tornado._ping_job is not None:
self.server._tornado._ping_job.stop()
示例5: worker
def worker():
io_loop = IOLoop()
server = Server({'/': modify_doc},
port=port,
io_loop=io_loop,
extra_patterns=[('/exit', _ExitHandler, dict(io_loop=io_loop))])
server.start()
server.io_loop.start()
示例6: run_server
def run_server(filename, config=None, path='/', port=5000):
"""Run the bokeh server."""
if config is None:
config = default_config(filename)
makedoc = make_makedoc(filename, config)
apps = {path: Application(FunctionHandler(makedoc))}
server = Server(apps, port=port, allow_websocket_origin=['*'])
server.run_until_shutdown()
示例7: Bokeh_Worker
class Bokeh_Worker(Thread):
# Init thread running server
def __init__(self, dev_app, trends_app, notes_app, serverIP, *, daemon=True):
Thread.__init__(self, daemon=daemon)
self._dev_app_ref = weakref.ref(dev_app)
self._trends_app_ref = weakref.ref(trends_app)
self._notes_app_ref = weakref.ref(notes_app)
self.IP = serverIP
self.exitFlag = False
def run(self):
self.process()
def process(self):
while not self.exitFlag:
self.task()
def startServer(self):
self.server = Server(
{
"/devices": self._dev_app_ref(),
"/trends": self._trends_app_ref(),
"/notes": self._notes_app_ref(),
},
io_loop=IOLoop(),
allow_websocket_origin=[
"{}:8111".format(self.IP),
"{}:5006".format(self.IP),
"{}:8111".format("localhost"),
"{}:5006".format("localhost"),
],
)
self.server.start()
self.server.io_loop.start()
def task(self):
try:
self.startServer()
except Exception as err:
self._log.warning("Bokeh server already running", err)
self.exitFlag = True
def stop(self):
self.bokeh_server.stop()
self.exitFlag = True
def beforeStop(self):
"""
Action done when closing thread
"""
pass
示例8: ManagedServerLoop
class ManagedServerLoop(object):
def __init__(self, application):
loop = IOLoop()
loop.make_current()
self._server = Server(application, io_loop=loop)
def __exit__(self, type, value, traceback):
self._server.unlisten()
self._server.io_loop.close()
def __enter__(self):
return self._server
@property
def io_loop(self):
return self.s_server.io_loop
示例9: func
def func(self, args):
if args.port >= 0:
self.port = args.port
self.develop_mode = args.develop
applications = self.build_applications(args)
# TODO make log level a command line option
logging.basicConfig(level=logging.DEBUG)
server = Server(applications, port=self.port)
if self.develop_mode:
log.info("Using develop mode (do not enable --develop in production)")
log.info("Starting Bokeh server on port %d with apps at %r", server.port, sorted(applications.keys()))
server.start()
示例10: invoke
def invoke(self, args):
applications = build_single_handler_applications(args.files)
log_level = getattr(logging, args.log_level.upper())
logging.basicConfig(level=log_level)
if len(applications) == 0:
# create an empty application by default, typically used with output_server
applications['/'] = Application()
if args.keep_alive is not None:
if args.keep_alive == 0:
log.info("Keep-alive ping disabled")
else:
log.info("Keep-alive ping configured every %d milliseconds", args.keep_alive)
# rename to be compatible with Server
args.keep_alive_milliseconds = args.keep_alive
server_kwargs = { key: getattr(args, key) for key in ['port',
'address',
'host',
'prefix',
'keep_alive_milliseconds']
if getattr(args, key, None) is not None }
server = Server(applications, **server_kwargs)
if args.show:
# we have to defer opening in browser until we start up the server
def show_callback():
for route in applications.keys():
server.show(route)
server.io_loop.add_callback(show_callback)
if args.develop:
log.info("Using develop mode (do not enable --develop in production)")
address_string = ''
if server.address is not None and server.address != '':
address_string = ' address ' + server.address
log.info("Starting Bokeh server on port %d%s with applications at paths %r",
server.port,
address_string,
sorted(applications.keys()))
server.start()
示例11: invoke
def invoke(self, args):
log_level = getattr(logging, args.log_level.upper())
logging.basicConfig(level=log_level, format=args.log_format)
applications = {}
_allowed_keys = ['port', 'address']
server_kwargs = { key: getattr(args, key) for key in _allowed_keys if getattr(args, key, None) is not None }
server = Server(applications, **server_kwargs)
address_string = ''
if server.address is not None and server.address != '':
address_string = ' address ' + server.address
log.info("Starting Bokeh static server on port %d%s", server.port, address_string)
server.start()
示例12: finish
def finish(self):
if not self.disable_server:
def modify_doc(doc):
doc.add_root(self.layout)
doc.title = self.name
directory = os.path.abspath(os.path.dirname(__file__))
theme_path = os.path.join(directory, "theme.yaml")
template_path = os.path.join(directory, "templates")
doc.theme = Theme(filename=theme_path)
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_path)
)
doc.template = env.get_template('index.html')
self.log.info('Opening Bokeh application on '
'http://localhost:{}/'.format(self.port))
server = Server({'/': modify_doc}, num_procs=1, port=self.port)
server.start()
server.io_loop.add_callback(server.show, "/")
server.io_loop.start()
示例13: listen
def listen(self, port):
if self.server:
return
for i in range(5):
try:
self.server = Server(self.apps, io_loop=self.loop, port=port,
check_unused_sessions_milliseconds=500,
host=['*'])
self.server.start(start_loop=False)
break
except (SystemExit, EnvironmentError):
port = 0
if i == 4:
raise
示例14: startServer
def startServer(self):
self.server = Server(
{
"/devices": self._dev_app_ref(),
"/trends": self._trends_app_ref(),
"/notes": self._notes_app_ref(),
},
io_loop=IOLoop(),
allow_websocket_origin=[
"{}:8111".format(self.IP),
"{}:5006".format(self.IP),
"{}:8111".format("localhost"),
"{}:5006".format("localhost"),
],
)
self.server.start()
self.server.io_loop.start()
示例15: listen
def listen(self, addr):
if self.server:
return
if isinstance(addr, tuple):
ip, port = addr
else:
port = addr
ip = None
for i in range(5):
try:
self.server = Server(self.apps,
port=port, address=ip,
check_unused_sessions_milliseconds=500,
allow_websocket_origin=["*"],
use_index=False,
extra_patterns=[(r'/', web.RedirectHandler, {'url': '/status'})],
**self.server_kwargs)
self.server.start()
handlers = [(self.prefix + r'/statics/(.*)',
web.StaticFileHandler,
{'path': os.path.join(os.path.dirname(__file__), 'static')})]
self.server._tornado.add_handlers(r'.*', handlers)
return
except (SystemExit, EnvironmentError) as exc:
if port != 0:
if ("already in use" in str(exc) or # Unix/Mac
"Only one usage of" in str(exc)): # Windows
msg = ("Port %d is already in use. "
"\nPerhaps you already have a cluster running?"
"\nHosting the diagnostics dashboard on a random port instead."
% port)
else:
msg = "Failed to start diagnostics server on port %d. " % port + str(exc)
warnings.warn('\n' + msg)
port = 0
if i == 4:
raise