pynput
pynput copied to clipboard
AttributeError: record_create_context
Description
I am trying to use pynput and getting the exception AttributeError: record_create_context
Platform and pynput version
System is Ubuntu 22.04: Linux mimzy-jetson 5.15.122-tegra #1 SMP PREEMPT Mon Dec 18 21:24:25 PST 2023 aarch64 aarch64 aarch64 GNU/Linux
Version 1.7.6
To Reproduce
Unfortunately my problem is a little more complex. I have a SoundRecorder
class that has a threaded function that does the actual recording. Here is the main
block of code. I don't understand this exception.
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
parser = argparse.ArgumentParser()
# Vision
parser.add_argument(
"-d", "--device_name",
type=str,
default=None,
help='Audio device name. e.g. python3 -m sounddevice'
)
args = parser.parse_args()
if args.device_name is None:
dname = 'default'
else:
dname = args.device_name
# start recorder thread
recorder = SoundRecorder(dname)
def on_press(key):
if key == keyboard.Key.space:
logging.info(f'[{_FILE.stem}] - Started recording - {key}')
recorder.start()
else:
logging.info(f'[{_FILE.stem}] incorrect character {key}, press space')
def on_release(key):
logging.info(f'[{_FILE.stem}] {key} released')
if key == keyboard.Key.space:
logging.info(f'[{_FILE.stem}] {key} stop')
recorder.stop()
return False
while True:
# monitor keyboard
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
if not recorder.is_recording():
logging.info(f"[{_FILE.stem}] READY")
The full stack trace
[mimzy_lam] Recording device: <Microphone PowerConf S3 Mono (1 channels)>
Traceback (most recent call last):
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/Xlib/display.py", line 224, in __getattr__
function = self.display_extension_methods[attr]
KeyError: 'record_create_context'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/pynput/_util/__init__.py", line 411, in receive
yield
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/pynput/keyboard/_xorg.py", line 545, in _run
super(Listener, self)._run()
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/pynput/_util/xorg.py", line 386, in _run
self._context = dm.record_create_context(
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/Xlib/display.py", line 227, in __getattr__
raise AttributeError(attr)
AttributeError: record_create_context
python-BaseException
Exception in thread Thread-6:
Traceback (most recent call last):
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/Xlib/display.py", line 224, in __getattr__
function = self.display_extension_methods[attr]
KeyError: 'record_create_context'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/pynput/_util/__init__.py", line 210, in run
self._run()
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/pynput/keyboard/_xorg.py", line 545, in _run
super(Listener, self)._run()
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/pynput/_util/xorg.py", line 386, in _run
self._context = dm.record_create_context(
File "/home/bryan/.cache/pypoetry/virtualenvs/mimzy-8gc2sb4S-py3.10/lib/python3.10/site-packages/Xlib/display.py", line 227, in __getattr__
raise AttributeError(attr)
AttributeError: record_create_context