Skip to content

Commit fd6aeef

Browse files
committed
Skip repeated events
1 parent a0fb5d9 commit fd6aeef

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pyprland/command.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import sys
99
from typing import cast
10+
from collections import defaultdict
1011

1112
from .common import PyprError, get_logger, init_logger
1213
from .ipc import get_event_stream
@@ -93,6 +94,7 @@ async def _callHandler(self, full_name, *params):
9394

9495
async def read_events_loop(self):
9596
"Consumes the event loop and calls corresponding handlers"
97+
last_cmd_args: dict[str, None | str] = defaultdict(lambda: None)
9698
while not self.stopped:
9799
try:
98100
data = (await self.event_reader.readline()).decode()
@@ -103,10 +105,13 @@ async def read_events_loop(self):
103105
self.log.critical("Reader starved")
104106
return
105107
cmd, params = data.split(">>", 1)
106-
full_name = f"event_{cmd}"
108+
last_args = last_cmd_args.get(cmd)
109+
if params != last_args:
110+
full_name = f"event_{cmd}"
107111

108-
# self.log.debug("[%s] %s", cmd, params.strip())
109-
await self._callHandler(full_name, params)
112+
# self.log.debug("[%s] %s", cmd, params.strip())
113+
await self._callHandler(full_name, params)
114+
last_cmd_args[cmd] = params
110115

111116
async def read_command(self, reader, writer) -> None:
112117
"Receives a socket command"

0 commit comments

Comments
 (0)