7.1.1.17. 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[~schedula.utils.drw.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 195 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">a</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=a] 196 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">b</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=b] 197 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2">c</TD></TR></TABLE>> fillcolor=cyan shape=box style="rounded,filled" tooltip=c] 198 [label=<<TABLE border="0" cellspacing="0"><TR><TD border="0" colspan="2" href="./dispatcher-4c58ed1f91d2ba767009c023dc42336977979c35/fun.html">fun</TD></TR></TABLE>> fillcolor=springgreen shape=box tooltip=fun] 198 -> 196 195 -> 198 198 -> 197 }

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.