7.2.8.17.11. web¶
- MapDispatch.web(depth=-1, node_data=none, node_function=none, directory=None, sites=None, run=True, subsite_idle_timeout=600)
Creates a dispatcher Flask app.
- Parameters:
depth (int, optional) – Depth of sub-dispatch API. If negative all levels are configured.
node_data (tuple[str], optional) – Data node attributes to produce API.
node_function (tuple[str], optional) – Function node attributes produce API.
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?
subsite_idle_timeout (int, optional) – Idle timeout of a debug subsite in seconds.
- 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:
>>> print("Starting...\n"); site = dsp.web(); 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.