7.2.8.20.6. web¶
-
SubDispatchPipe.
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: 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'
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.