Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: read all chunks in queue since we have interval in listener #337

Merged
merged 1 commit into from
Jan 24, 2025
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
11 changes: 6 additions & 5 deletions pytest-embedded/pytest_embedded/dut_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ def msg_queue_gn() -> MessageQueue:
def _listen(q: MessageQueue, filepath: str, with_timestamp: bool = True, count: int = 1, total: int = 1) -> None:
_added_prefix = False
while True:
msg = q.get()
if not msg:
msgs = q.get_all()
if not msgs:
hfudev marked this conversation as resolved.
Show resolved Hide resolved
continue

msg_b = b''.join(msgs)
with open(filepath, 'ab') as fw:
fw.write(msg)
fw.write(msg_b)
fw.flush()

_s = to_str(msg)
_s = to_str(msg_b)
if not _s:
continue

Expand All @@ -87,7 +88,7 @@ def _listen(q: MessageQueue, filepath: str, with_timestamp: bool = True, count:

_stdout.write(_s)
_stdout.flush()
time.sleep(0.1)
time.sleep(0.05)


def _listener_gn(msg_queue, _pexpect_logfile, with_timestamp, dut_index, dut_total) -> multiprocessing.Process:
Expand Down
14 changes: 14 additions & 0 deletions pytest-embedded/pytest_embedded/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import textwrap
import uuid
from multiprocessing import queues
from queue import Empty
from typing import AnyStr, List, Optional, Union

import pexpect.fdpexpect
Expand All @@ -26,6 +27,8 @@ class MessageQueue(queues.Queue):
def __init__(self, *args, **kwargs):
if 'ctx' not in kwargs:
kwargs['ctx'] = _ctx

self.lock = _ctx.Lock()
super().__init__(*args, **kwargs)

def put(self, obj, **kwargs):
Expand All @@ -42,6 +45,17 @@ def put(self, obj, **kwargs):
except: # noqa # queue might be closed
pass

def get_all(self) -> List[bytes]:
res = []
with self.lock:
hfudev marked this conversation as resolved.
Show resolved Hide resolved
while True:
try:
res.append(self.get_nowait())
except Empty:
break

return res

def write(self, s: AnyStr):
self.put(s)

Expand Down
Loading