Skip to content

Commit

Permalink
Use the highest available pickle protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf committed Sep 26, 2019
1 parent 60dec3a commit 02306be
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lahja/asyncio/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def connect_to(cls, path: Path) -> ConnectionAPI:
return cls(reader, writer)

async def send_message(self, message: Msg) -> None:
pickled = pickle.dumps(message)
pickled = pickle.dumps(message, protocol=pickle.HIGHEST_PROTOCOL)
size = len(pickled)

try:
Expand Down
5 changes: 4 additions & 1 deletion lahja/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,10 @@ def _compress_event(self, event: BaseEvent) -> Union[BaseEvent, bytes]:
if self.has_snappy_support:
import snappy

return cast(bytes, snappy.compress(pickle.dumps(event)))
return cast(
bytes,
snappy.compress(pickle.dumps(event, protocol=pickle.HIGHEST_PROTOCOL))
)
else:
return event

Expand Down
2 changes: 1 addition & 1 deletion lahja/trio/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def connect_to(cls, path: pathlib.Path) -> "TrioConnection":
return cls(socket)

async def send_message(self, message: Msg) -> None:
msg_data = pickle.dumps(message)
msg_data = pickle.dumps(message, protocol=pickle.HIGHEST_PROTOCOL)
size = len(msg_data)
try:
async with self._write_lock:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/156.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure ``stream()`` does not suppress ``CancelledError``
3 changes: 3 additions & 0 deletions newsfragments/160.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Use the highest available `pickle` protocol. This yields a notable performance
improvement on Python < 3.8 which are still using version 3 of the protocol by
default.
1 change: 0 additions & 1 deletion newsfragments/feature.156.rst

This file was deleted.

2 changes: 1 addition & 1 deletion tests/core/asyncio/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,4 @@ def test_pickle_fails():
alice = AsyncioEndpoint("pickle-test")

with pytest.raises(Exception):
pickle.dumps(alice)
pickle.dumps(alice, protocol=pickle.HIGHEST_PROTOCOL))

0 comments on commit 02306be

Please sign in to comment.