-
-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
010f896
commit a387b3b
Showing
11 changed files
with
222 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from __future__ import annotations | ||
|
||
import pickle | ||
from collections.abc import Iterator | ||
from typing import Any | ||
|
||
from distributed.protocol.utils import pack_frames_prelude, unpack_frames | ||
|
||
|
||
def pickle_bytelist(obj: object) -> list[bytes | memoryview]: | ||
"""Variant of :func:`serialize_bytelist`, that doesn't support compression, locally | ||
defined classes, or any of its other fancy features but runs 10x faster for numpy | ||
arrays | ||
See Also | ||
-------- | ||
serialize_bytelist | ||
unpickle_bytestream | ||
""" | ||
frames: list = [] | ||
pik = pickle.dumps( | ||
obj, protocol=5, buffer_callback=lambda pb: frames.append(pb.raw()) | ||
) | ||
frames.insert(0, pik) | ||
frames.insert(0, pack_frames_prelude(frames)) | ||
return frames | ||
|
||
|
||
def unpickle_bytestream(b: bytes | bytearray | memoryview) -> Iterator[Any]: | ||
"""Unpickle the concatenated output of multiple calls to :func:`pickle_bytelist` | ||
See Also | ||
-------- | ||
pickle_bytelist | ||
deserialize_bytes | ||
""" | ||
while True: | ||
pik, *buffers, remainder = unpack_frames(b, remainder=True) | ||
yield pickle.loads(pik, buffers=buffers) | ||
if remainder.nbytes == 0: | ||
break | ||
b = remainder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.