8.1.1.19. web

Dispatcher.web(depth=-1, node_data=none, node_function=none, directory=None, sites=None, run=True)

Creates a dispatcher Flask app.

Parameters:
  • depth (int, optional) – Depth of sub-dispatch plots. If negative all levels are plotted.
  • node_data (tuple[str], optional) – Data node attributes to view.
  • node_function (tuple[str], optional) – Function node attributes to view.
  • directory (str, optional) – Where is the generated Flask app root located?
  • sites (set[Site], optional) – A set of Site to maintain alive the backend server.
  • run (bool, optional) – Run the backend server?
Returns:

A WebMap.

Return type:

WebMap

Example:

From a dispatcher like this:

>>> from schedula import Dispatcher
>>> dsp = Dispatcher(name='Dispatcher')
>>> def fun(a):
...     return a + 1, a - 1
>>> dsp.add_function('fun', fun, ['a'], ['b', 'c'])
'fun'

digraph dmap { graph [ratio=1] node [style=filled] label = <dmap> splines = ortho style = filled 240 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">a</TD></TR></TABLE>> fillcolor=cyan id=1 shape=box style="rounded,filled" tooltip="\"a\""] 241 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">b</TD></TR></TABLE>> fillcolor=cyan id=2 shape=box style="rounded,filled" tooltip="\"b\""] 242 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">c</TD></TR></TABLE>> fillcolor=cyan id=3 shape=box style="rounded,filled" tooltip="\"c\""] 243 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-72515939cbd07204e000c3fd48b8bc44e36e3497/fun.html">fun</TD></TR></TABLE>> fillcolor=springgreen id=0 shape=box tooltip="\"fun\""] 243 -> 241 243 -> 242 240 -> 243 }

You can create a web server with the following steps:

>>> webmap = dsp.web()
>>> print("Starting...\n"); site = webmap.site().run(); site
Starting...
Site(WebMap([(Dispatcher, WebMap())]), host='localhost', ...)
>>> import requests
>>> url = '%s/%s/%s' % (site.url, dsp.name, fun.__name__)
>>> requests.post(url, json={'args': (0,)}).json()['return']
[1, -1]
>>> site.shutdown()  # Remember to shutdown the server.
True

Note

When Site is garbage collected the server is shutdown automatically.