Skip to content

Commit

Permalink
Do not always check if __main__ in result when pickling (dask#8443)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjetter authored Jan 10, 2024
1 parent 964abea commit 5c481dd
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions distributed/protocol/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ def dumps(x, *, buffer_callback=None, protocol=HIGHEST_PROTOCOL):
buffers.clear()
pickler.dump(x)
result = f.getvalue()
if b"__main__" in result or (

if not _always_use_pickle_for(x) and (
CLOUDPICKLE_GE_20
and getattr(inspect.getmodule(x), "__name__", None)
in cloudpickle.list_registry_pickle_by_value()
or (
len(result) < 1000
# Do this very last since it's expensive
and b"__main__" in result
)
):
if len(result) < 1000 or not _always_use_pickle_for(x):
buffers.clear()
result = cloudpickle.dumps(x, **dump_kwargs)
buffers.clear()
result = cloudpickle.dumps(x, **dump_kwargs)
except Exception:
try:
buffers.clear()
Expand Down

0 comments on commit 5c481dd

Please sign in to comment.