Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
Small followup to #1456
  • Loading branch information
albertz committed Nov 8, 2023
1 parent 09adef0 commit ff7569f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions returnn/util/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import re
import time
import contextlib
import struct

try:
import thread
Expand Down Expand Up @@ -2624,11 +2625,10 @@ def read_pickled_object(p: typing.BinaryIO, *, encoding=None) -> Any:
:param encoding: if given, passed to Unpickler
"""
from returnn.util.task_system import Unpickler
import struct

size_raw = read_bytes_to_new_buffer(p, 4)
(size,) = struct.unpack("<i", size_raw)
assert size > 0, "%s: We expect to get some non-empty package. Invalid Python mod in Sprint?" % (self,)
assert size > 0, "read_pickled_object: We expect to get some non-empty package."
stream = read_bytes_to_new_buffer(p, size)
unpickler_kwargs = {}
if encoding:
Expand All @@ -2640,8 +2640,10 @@ def write_pickled_object(p: typing.BinaryIO, obj: Any):
"""
Writes pickled object to stream p.
"""
stream = io.BytesIO()
Pickler(stream).dump(data)
from returnn.util.task_system import Pickler

stream = BytesIO()
Pickler(stream).dump(obj)
raw_data = stream.getvalue()
assert len(raw_data) > 0
p.write(struct.pack("<i", len(raw_data)))
Expand Down

0 comments on commit ff7569f

Please sign in to comment.