Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion can/io/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from abc import ABC, abstractmethod
from collections.abc import Callable
from datetime import UTC, datetime
from functools import cache
from types import TracebackType
from typing import (
Any,
Expand Down Expand Up @@ -50,8 +51,9 @@
}


@cache
def _update_writer_plugins() -> None:
"""Update available message writer plugins from entry points."""
"""Discover available message writer plugins once per process."""
for entry_point in read_entry_points("can.io.message_writer"):
if entry_point.key in MESSAGE_WRITERS:
continue
Expand Down
4 changes: 3 additions & 1 deletion can/io/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pathlib
import time
from collections.abc import Generator, Iterable
from functools import cache
from typing import (
Any,
Final,
Expand Down Expand Up @@ -38,8 +39,9 @@
}


@cache
def _update_reader_plugins() -> None:
"""Update available message reader plugins from entry points."""
"""Discover available message reader plugins once per process."""
for entry_point in read_entry_points("can.io.message_reader"):
if entry_point.key in MESSAGE_READERS:
continue
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/2155.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid rescanning installed entry points for every Logger and LogReader construction.
13 changes: 13 additions & 0 deletions test/logformats_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ def _test_extension(self, suffix):
finally:
os.remove(tmp_file.name)

@parameterized.expand([(can.Logger,), (can.LogReader,)])
def test_repeated_handlers_do_not_rescan_plugins(self, factory):
with tempfile.TemporaryDirectory() as directory:
filename = Path(directory) / "record.asc"
filename.touch()
with factory(filename):
pass
with patch("can._entry_points.entry_points") as discover:
for _ in range(3):
with factory(filename):
pass
discover.assert_not_called()

def test_extension_matching_asc(self):
self._test_extension(".asc")

Expand Down
Loading