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
I can't use pynput in MacOS Monterey 12.0.1 + M1 environment #424
Comments
I made a temporary solution, but I hope the author can help to see why drawin.py
|
Thank you for your report and proposed fix. I think your proposition is the way to go; previously this library used a function loaded by I have included your fix in the branch |
I've tested this branch on my M1 mbp with Big Sur, no errors like before. Maybe you could merge it now. |
I'm having similar issues with my M1 mac running macOS Ventura but only when I use pynput with Qt... seems to fail similarly to the above issue with I have rearranged Qt / pynput startup order and encountered some lazy load race conditions / timing issues with pyobjc behind the scenes such that I can get both to work in simple setups but I have another setup where I'm getting the following trace and haven't had much luck finding out why... I'll keep plugging away on it and share what I find. All of the issues I've had (race conditions, and the following) stem from the same spot (or nearby) with regards to the keycode_context creation and involve Carbon API calls.
|
I also ran into a crash when |
In my case, I'm also using a QT as a frontend. I'm creating a Controller at the start, and a Listener on demand. My app crashes when starting the Listener. I've modified _wrap_value in _util/darwin.py to log some info: def _wrap_value(value):
"""Converts a pointer to a *Python objc* value.
:param value: The pointer to convert.
:return: a wrapped value
"""
print(f"Called _wrap_value({value})")
object = objc.objc_object(c_void_p=value) if value is not None else None
print(f"Called _wrap_value({value}) = {object}")
return object When loading Controller at the start, I get this:
And then, when starting the listener:
And then it crashes. Maybe it has something to do with the pointer being reused? EDIT: Turned off the Controller, and the Listener keeps crashing the app :( |
It’s an issue with pyobjc and how it registers/resolves arg types and
results
try adding this when your script/program starts up (before invoking pynput)
and see if the issue resolves:
import objc
import CoreFoundation
objc.registerCFSignature("CFStringRef", b"^{__CFString=}",
CoreFoundation.CFStringGetTypeID(), "NSString")
…On Fri, Oct 21, 2022 at 9:26 AM Alvaro ***@***.***> wrote:
In my case, I'm also using a QT as a frontend. I'm creating a Controller
at the start, and a Listener on demand.
I've modified _wrap_value in _util/darwin.py to log some info:
def _wrap_value(value):
"""Converts a pointer to a *Python objc* value. :param value: The pointer to convert. :return: a wrapped value """
print(f"Called _wrap_value({value})")
object = objc.objc_object(c_void_p=value) if value is not None else None
print(f"Called _wrap_value({value}) = {object}")
return object
When loading Controller at the start, I get this:
Called _wrap_value(4649539536)
Called _wrap_value(4649539536) = <TSMInputSource 0x1152257d0> KB Layout: Latin American (id=89)
Called _wrap_value(5195413504)
Called _wrap_value(5195413504) = b'\x02\x10\x00\x01\x00\x03\x00\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x03\x00\x00<\x1c\x00\x00P"\x00\x00\...
And then, when starting the listener:
Called _wrap_value(4649539536)
And then it crashes. Maybe it has something to do with the pointer being
reused?
—
Reply to this email directly, view it on GitHub
<#424 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABL7XPNHJN46ZFW6QZXR5TWEKRZHANCNFSM5I6ZI2FQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Sadly, no, it keeps crashing only when Listener.start/join is called, even if Controller is not started, but my bug seems to be a new one... ... Something to do with the thread it's running in. The Controller is called on the main thread, while the listener in its own new thread. If I start the Controller and the Listener in the same object the application doesn't crash. This MUST be a bug with objc way of creating objects from pointers. This line is the culprit: pynput/lib/pynput/_util/darwin.py Line 45 in 078491e
When invoking that line on creating a Listener from a new thread, on MacOS Monterey Apple Silicon, it crashes. The same software on Windows runs fine. |
So @g0t4 is right on this one. If I start the pynput keyboard Listener before QT, it works. But if I start it after QT, it fails and crashes the app. |
@g0t4 Hi! I'm having an issue with all the same symptoms as this, only using Is there an issue we can file with Thank you. |
Also impractical for me, and this is enough of a blocker that I'll have to switch away to another library. @moses-palmer can we reopen this issue for more visibility please? |
@Raymo111, sure, I'll reopen. |
Description
Hello, I want to ask for help, I can't use pynput in MacOS Monterey 12.0.1 + M1 environment
Platform and pynput version
System:macOS Monterey 12.0.1 + M1
pynput 1.7.5
python 3.8
To Reproduce
Use official examples
The text was updated successfully, but these errors were encountered: