mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-21 02:26:10 +00:00
feat(python): ignore unrelated responses
Old responses may be still in the receive queue (blocking the device from handling new requests). Let's "flush" them before starting the test. [no changelog]
This commit is contained in:
parent
e1ce484ba7
commit
49c9ad04cd
@ -21,7 +21,7 @@ import struct
|
||||
|
||||
from typing_extensions import Protocol as StructuralType
|
||||
|
||||
from . import MessagePayload, Transport
|
||||
from . import MessagePayload, Timeout, Transport
|
||||
|
||||
REPLEN = 64
|
||||
|
||||
@ -82,6 +82,14 @@ class Protocol:
|
||||
def begin_session(self) -> None:
|
||||
if self.session_counter == 0:
|
||||
self.handle.open()
|
||||
try:
|
||||
# Drop queued responses to old requests
|
||||
while True:
|
||||
msg = self.handle.read_chunk(timeout=0.1)
|
||||
LOG.warning("ignored: %s", msg)
|
||||
except Timeout:
|
||||
pass
|
||||
|
||||
self.session_counter += 1
|
||||
|
||||
def end_session(self) -> None:
|
||||
|
@ -28,7 +28,7 @@ from .protocol import ProtocolBasedTransport, ProtocolV1
|
||||
if TYPE_CHECKING:
|
||||
from ..models import TrezorModel
|
||||
|
||||
SOCKET_TIMEOUT = 10
|
||||
SOCKET_TIMEOUT = 0.1
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user