Serialize obj as a string of bytes allocated in memory protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to pickle.HIGHEST_PROTOCOL. This setting favors maximum communication speed between processes running the same Python version. Set protocol=pickle.DEFAULT_PROT
(obj, protocol=None, buffer_callback=None)
| 1541 | |
| 1542 | |
| 1543 | def dumps(obj, protocol=None, buffer_callback=None): |
| 1544 | """Serialize obj as a string of bytes allocated in memory |
| 1545 | |
| 1546 | protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to |
| 1547 | pickle.HIGHEST_PROTOCOL. This setting favors maximum communication |
| 1548 | speed between processes running the same Python version. |
| 1549 | |
| 1550 | Set protocol=pickle.DEFAULT_PROTOCOL instead if you need to ensure |
| 1551 | compatibility with older versions of Python (although this is not always |
| 1552 | guaranteed to work because cloudpickle relies on some internal |
| 1553 | implementation details that can change from one Python version to the |
| 1554 | next). |
| 1555 | """ |
| 1556 | with io.BytesIO() as file: |
| 1557 | cp = Pickler(file, protocol=protocol, buffer_callback=buffer_callback) |
| 1558 | cp.dump(obj) |
| 1559 | return file.getvalue() |
| 1560 | |
| 1561 | |
| 1562 | # Include pickles unloading functions in this namespace for convenience. |