Commit 8382caa5 authored by Jakob Moser's avatar Jakob Moser
Browse files

Merge branch 'mock' into 'master'

Improve --mock handling

See merge request !40
parents 2d6c7f6f 44f21d9c
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for README.md: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -277,7 +277,7 @@ You can run the application in mock mode, which will simulate display, touch scr
uv run -m poolpay --mock
```

The mock card reader will listen on the command line for an integer card id, usually followed by `r` to simulate card removal. Quitting the program should work via <kbd>Ctrl</kbd>+<kbd>C/<kbd>, although it seems like not all threads immediately terminate, i.e., you might need to press it several times.
The mock card reader will listen on the command line for an integer card id, usually followed by `r` to simulate card removal. Quitting the program works via <kbd>Ctrl</kbd>+<kbd>C/<kbd>.

## License

+8 −1
Changes for poolpay/card/MockCardReader.py: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
from __future__ import annotations

import sys
from collections.abc import Callable
from dataclasses import dataclass, field

@@ -18,7 +19,13 @@ class MockCardReader(CardReader):

    def on_card_placed(self, handle_card: Callable[[CardReader], None]) -> None:
        while True:
            line = input("Card ID (int) or 'r' to remove card> ").strip()
            print("Card ID (int) or 'r' to remove card> ", end="", flush=True)

            # Using sys.stdin.readline instead of input seems to avoid 'Fatal Python error: _enter_buffered_busy:
            # could not acquire lock for <_io.BufferedReader name='<stdin>'> at interpreter shutdown,
            # possibly due to daemon threads' on terminate. I don't know why (does input hold a lock on stdin,
            # but readline doesn't?), but given that this is only for the mock mode, I'll accept this for now.
            line = sys.stdin.readline().strip()

            if line.lower() == "r":
                if self._card_id is not None:
+1 −0
Changes for poolpay/display/PygameMockDisplay.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ class MockDisplayThread(Thread):

    def run(self) -> None:
        pygame.init()
        pygame.display.set_caption("PoolPay")

        while True:
            request = self._request_queue.get(block=True)