Skip to content

Commit

Permalink
Fix clear serializers behaviour after master merge
Browse files Browse the repository at this point in the history
  • Loading branch information
benclifford committed Jul 20, 2023
1 parent 2e8bdea commit ed759dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
34 changes: 21 additions & 13 deletions parsl/serialize/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@
deserializers = {}


def clear_serializers() -> None:
# does not clear deserializers because remote sending back will have a
# different serializer list (and wants to send back results with one of
# the default 4) so clearing all the deserializers means we cannot receive
# results...
global methods_for_data, methods_for_code
methods_for_code = []
methods_for_data = []
# maybe it's weird to want to clear away all serializers rather than just the
# data or just code ones? eg in proxystore test, clearing serializers means
# there is no code serializer... so just data sreializer should be cleared
# (or if only having one kind of serializer, no code/data distinction, then
# this is more consistent, but clearing serializer is still a bit weird in
# that case (maybe for security?) - with inserting one near the start more
# usual?
# def clear_serializers() -> None:
# # does not clear deserializers because remote sending back will have a
# # different serializer list (and wants to send back results with one of
# # the default 4) so clearing all the deserializers means we cannot receive
# # results...
# global methods_for_data, methods_for_code
# methods_for_code = []
# methods_for_data = []


def unregister_serializer(serializer: SerializerBase) -> None:
Expand Down Expand Up @@ -121,6 +128,9 @@ def serialize(obj: Any, buffer_threshold: int = int(1e6)) -> bytes:
else:
methods = methods_for_data

if methods == []:
raise RuntimeError("There are no configured serializers")

for method in methods:
try:
logger.info(f"BENC: trying serializer {method}")
Expand All @@ -132,15 +142,13 @@ def serialize(obj: Any, buffer_threshold: int = int(1e6)) -> bytes:
else:
break

# if no serializer found
if result is None:
logger.error("BENC: no serializer returned a result")
raise RuntimeError("BENC: No serializers")
raise RuntimeError("No serializer returned a result")
elif isinstance(result, BaseException):
logger.error("BENC: exception from final serializer")
logger.error("Serializer returned an excepton, reraise")
raise result
else:
logger.info("BENC: serialization complete")
logger.debug("Serialization complete")
if len(result) > buffer_threshold:
logger.warning(f"Serialized object exceeds buffer threshold of {buffer_threshold} bytes, this could cause overflows")
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from parsl.tests.configs.htex_local import fresh_config as local_config

from parsl.serialize.base import SerializerBase
from parsl.serialize.facade import serialize, deserialize, register_method_for_data, unregister_serializer, clear_serializers
from parsl.serialize.facade import serialize, deserialize, register_method_for_data, unregister_serializer

from parsl.serialize.plugin_proxystore_deep_pickle import create_deep_proxystore_serializer

Expand Down Expand Up @@ -42,7 +42,10 @@ def __str__(self):
def test_proxystore_single_call():
later_c = [v for v in parsl.serialize.facade.methods_for_code]
later_d = [v for v in parsl.serialize.facade.methods_for_data]
clear_serializers()

# clear the data serializers, leaving the code serializers in place
parsl.serialize.facade.methods_for_data = []

s = create_deep_proxystore_serializer(policy=MyDemo)

register_method_for_data(s)
Expand Down

0 comments on commit ed759dc

Please sign in to comment.