This class provides a common streaming approach for the purpose of reliably sending data over a socket interface. More...
Public Member Functions | |
| def | __init__ (self, fp) |
| Stream handler that encodes objects as either JSON (if available) with message length header prepended for sending over a socket, or as a pickled object if using python < 2.6 and simplejson is not installed. More... | |
| def | dump (self, obj) |
| Similar method to json dump, prepending data with message length header. More... | |
| def | load (self) |
| Reads in json message prepended with message length header from a file (or socket, or other .read() enabled object). More... | |
Public Attributes | |
| fp | |
Static Public Attributes | |
| dumps = staticmethod(dumps) | |
| loads = staticmethod(loads) | |
Private Member Functions | |
| def | _load_header (self) |
Private Attributes | |
| _json_decoder | |
| _json_encoder | |
This class provides a common streaming approach for the purpose of reliably sending data over a socket interface.
Replaces usage of Unpickler.load where possible with JSON format prepended by message length header. Uses json in python stdlib (in python >= 2.6) or simplejson (in python < 2.6). If neither are available, falls back to pickle.Pickler and pickle.Unpickler, attempting to eliminate memory leakage where possible at the expense of CPU usage (by not re-using Pickler or Unpickler objects).
NOTE: StreamHandler currently assumes that same python version is installed on both sides of reading/writing (or simplejson is loaded in case of one side or other using python < 2.6). This could be resolved by requiring an initial header with json vs pickle determination from the writing side, but would considerably complicate the protocol(s) further (handshake would need to occur at least, and assumes encoding is used over a socket, etc.)
json.raw_decode could be used rather than prepending with a message header in theory (assuming json is available), but performance of repeatedly failing to parse written data would make this an unworkable solution in many cases.
Definition at line 457 of file TestRunnerAgent.py.
| def robotide.contrib.testrunner.TestRunnerAgent.StreamHandler.__init__ | ( | self, | |
| fp | |||
| ) |
Stream handler that encodes objects as either JSON (if available) with message length header prepended for sending over a socket, or as a pickled object if using python < 2.6 and simplejson is not installed.
Since pickle.load has memory leak issues with memoization (remembers absolutely everything decoded since instantiation), json is a preferred method to encode/decode for long running processes which pass large amounts of data back and forth.
Definition at line 471 of file TestRunnerAgent.py.
|
private |
Load in just the header bit from a socket/file pointer
Definition at line 546 of file TestRunnerAgent.py.
| def robotide.contrib.testrunner.TestRunnerAgent.StreamHandler.dump | ( | self, | |
| obj | |||
| ) |
Similar method to json dump, prepending data with message length header.
Replaces pickle.dump, so can be used in place without the memory leaks on receiving side in pickle.load (related to memoization of data)
NOTE: Protocol is ignored when json representation is used
Definition at line 492 of file TestRunnerAgent.py.
| def robotide.contrib.testrunner.TestRunnerAgent.StreamHandler.load | ( | self | ) |
Reads in json message prepended with message length header from a file (or socket, or other .read() enabled object).
Message is expected to be encoded by this class as well, to have same message length header type.
Specifically replaces pickle.load as that function/method has serious memory leak issues with long term use of same Unpickler object for encoding data to send, specifically related to memoization of data to encode.
Definition at line 521 of file TestRunnerAgent.py.
|
private |
Definition at line 475 of file TestRunnerAgent.py.
|
private |
Definition at line 473 of file TestRunnerAgent.py.
|
static |
Definition at line 459 of file TestRunnerAgent.py.
| robotide.contrib.testrunner.TestRunnerAgent.StreamHandler.fp |
Definition at line 482 of file TestRunnerAgent.py.
|
static |
Definition at line 458 of file TestRunnerAgent.py.