bag.interface.server
This class defines SkillOceanServer, a server that handles skill/ocean requests.
The SkillOceanServer listens for skill/ocean requests from bag. Skill commands will be forwarded to Virtuoso for execution, and Ocean simulation requests will be handled by starting an Ocean subprocess. It also provides utility for bag to query simulation progress and allows parallel simulation.
Client-side communication:
the client will always send a request object, which is a python dictionary. This script processes the request and sends the appropriate commands to Virtuoso.
Virtuoso side communication:
To ensure this process receive all the data from Virtuoso properly, Virtuoso will print a single line of integer indicating the number of bytes to read. Then, virtuoso will print out exactly that many bytes of data, followed by a newline (to flush the standard input). This script handles that protcol and will strip the newline before sending result back to client.
Module Contents
Classes
A server that handles skill commands. |
Functions
|
Recursive helper function for object_to_skill_file |
|
Write the given python object to a file readable by Skill. |
Attributes
- bag.interface.server._object_to_skill_file_helper(py_obj, file_obj)[source]
Recursive helper function for object_to_skill_file
- Parameters:
py_obj (any) – the object to convert.
file_obj (file) – the file object to write to. Must be created with bag.io package so that encodings are handled correctly.
- bag.interface.server.object_to_skill_file(py_obj, file_obj)[source]
Write the given python object to a file readable by Skill.
Write a Python object to file that can be parsed into equivalent skill object by Virtuoso. Currently only strings, lists, and dictionaries are supported.
- Parameters:
py_obj (any) – the object to convert.
file_obj (file) – the file object to write to. Must be created with bag.io package so that encodings are handled correctly.
- class bag.interface.server.SkillServer(router, virt_in, virt_out, tmpdir=None)[source]
Bases:
object
A server that handles skill commands.
This server is started and ran by virtuoso. It listens for commands from bag from a ZMQ socket, then pass the command to virtuoso. It then gather the result and send it back to bag.
- Parameters:
router (
bag.interface.ZMQRouter
) – theZMQRouter
object used for socket communication.virt_in (file) – the virtuoso input file. Must be created with bag.io package so that encodings are handled correctly.
virt_out (file) – the virtuoso output file. Must be created with bag.io package so that encodings are handled correctly.
tmpdir (str or None) – if given, will save all temporary files to this folder.
- send_skill(expr)[source]
Sends expr to virtuoso for evaluation.
- Parameters:
expr (string) – the skill expression.
- process_skill_request(request)[source]
Process the given skill request.
Based on the given request object, returns the skill expression to be evaluated by Virtuoso. This method creates temporary files for long input arguments and long output.
- Parameters:
request (dict) – the request object.
- Returns:
expr (str or None) – expression to be evaluated by Virtuoso. If None, an error occurred and nothing needs to be evaluated
out_file (str or None) – if not None, the result will be written to this file.