Skip to content

wrong repo. Sorry #81

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

Closed
Cube707 opened this issue Jul 9, 2022 · 0 comments
Closed

wrong repo. Sorry #81

Cube707 opened this issue Jul 9, 2022 · 0 comments

Comments

@Cube707
Copy link
Collaborator

Cube707 commented Jul 9, 2022

This version indeed solves issue 1 in #64 but unfortunately it doesn't fix issue 2 as per my test on my ovh server (running ubuntu). Below is my test script:

import sys
sys.path.insert(0, r"/root/python-readchar-v4")
from threading import Thread
from queue import Queue
from typing import Callable, Dict
import time
import logging
import readchar

logging.basicConfig(
    format='%(asctime)s - %(levelname)s - %(module)s - %(message)s', level=logging.INFO,
)

running = False


class KeyBoardMonitor(object):

    def __init__(self, callbacks: Dict[str, Callable[[str], None]] = None, quit_symbol: str = 'q'):
        self.callbacks = callbacks if callbacks else {}
        self.quit_symbol = quit_symbol
        self.running = True
        self.queue = Queue()
        self.thread = Thread(name="keyboard monitoring", target=self._keyboard_monitor)

    def register_callback(self, order: str, callback: Callable[[str], None]) -> None:
        self.callbacks[order] = callback

    def unregister_callback(self, order):
        del self.callbacks[order]

    def start(self):
        self.thread.start()

    def stop(self):
        self.running = False

    def _keyboard_monitor(self):
        while self.running:
            ch = str(readchar.readchar())
            if ch in self.callbacks:
                self.callbacks[ch](ch)
            if ch == self.quit_symbol:
                self.running = False

def myprint(ch):
    print(ch, "entered")
    if ch == 'q':
        global running
        running = False


if __name__=="__main__":
    watchdog = KeyBoardMonitor(callbacks={'q': myprint, 'p': myprint})
    watchdog.start()
    running = True
    for _ in range(300):
        if not running:
            break
        time.sleep(1)
        logging.info(f"current_time: {time.time()}")

copy this into file and change the path in sys.path.insert to the "master" branch of local clone of your repo in r"/root/python-readchar-v4", I still see unwanted blanks (should come from the \r generated by setraw and missing linebreaks between logs:
image

In contrast, if using my version in pull request #64, I can get clean log outputs.
image

Would you please take some further look?

Thanks!

_Originally posted by @qianyun210603 in github.com/magmax/python-readchar/issues/79#issuecomment-1179482070

@Cube707 Cube707 changed the title @Cube707 wrong repo. Sorry Jul 9, 2022
@Cube707 Cube707 closed this as completed Jul 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant