-
Notifications
You must be signed in to change notification settings - Fork 18
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
Crash on macOS Big Sur 11.4 #11
Comments
Also on Big Sur:
|
Are you using an M1 Mac or Intel Mac? |
Also could you trying running this code, for a bit more debugging info? import faulthandler
faulthandler.enable()
import darkdetect
print(darkdetect.theme()) |
I'm on Big Sur 11.5.2, but M1 MBP and having this same issue.
|
Wonder if this is related to the fact that running:
The same command, when run in Dark mode returns: |
Hmmm... interesting, perhaps using that command would be more reliable than using import subprocess
def theme():
sub = subprocess.Popen("defaults read -globalDomain AppleInterfaceStyle".split(), stdout=subprocess.PIPE)
result = sub.stdout.read()
if isinstance(result, bytes):
try:
result = result.decode()
except UnicodeDecodeError:
return 'Light'
if result[-1] == '\n':
result = result[:-1]
return 'Dark' if result == 'Dark' else 'Light' Not sure how this works with other versions of macOS though. Works well on my Intel Mac running Big Sur 11.4. |
I've used this python hack of a terminal command:
Works on Big Sur M1. Edit: Can report your code above using
|
Thanks to all for reporting and investigating this. I have also experienced this issue on Big Sur 11.3+ and an Intel Mac. What I find intriguing is that the issue occurs only when running the code from Terminal. If the code is called by a proper .app bundle (e.g. one frozen with py2app), then the detection always works as expected. To me, this and the error message we see ( @psobolewskiPhD @Ahsoka Detection methods based on command invocations + |
Maybe when not frozen you can use a command invocation for detection and when frozen use the Psuedo code: import sys
def theme():
if getattr(sys, 'frozen', False):
ctypes_method()
else:
command_invocation_method() |
I found the issue:
I now wonder how this worked from .app bundles, perhaps Patching darkdetect/darkdetect/_mac_detect.py Lines 10 to 11 in aa8a78e
appkit = ctypes.cdll.LoadLibrary('AppKit.framework/AppKit')
objc = ctypes.cdll.LoadLibrary('libobjc.dylib') allows me to correctly run the package from Terminal on Big Sur 11.3.1. I assume the change is not compatible with older macOS versions so, a proper fix will require to retain the old code for backward compatibility. Also, the effects of this change to .app bundles needs to be investigated. I intend to do this as soon as I have some spare time, then release a new version of Thanks again to all the people that contributed to this discussion. (Credits for the help I found in vispy/vispy#1885 and vispy/vispy#1975). |
Fixed in 0.4.0. |
See albertosottile/darkdetect#11 for reference
Alas, the issue is not resolved for me Big Sur 11.5.2 but on M1 mac
Edit: I tested in both light and dark mode. |
Hmmm... very interesting, the issue is resolved for me on my Intel Mac and it appears that @albertosottile also has an Intel Mac. Seems like a M1 Mac specific issue. |
That's what I feared 🦑
|
@psobolewskiPhD It appears we have two different issues at hand. Unfortunately, I do not have a M1 Mac to reproduce/debug this one. However, in this case I would ask you to open another issue on GitHub to better distinguish the latter bug from the one that I just patched. In case you want to do that, it might be a good idea to remove conda and ipython from the equation, and run directly |
I think I've narrowed it down. But in def theme(): This triggers segfault. You can do a simple test by using:
If the .argtypes is just [void_p, void_p] it segfaults, if it's [void_p, void_p, void_p] it runs. I've fixed it locally, by making the .argtypes have 3 arguments and then passing None as the third everywhere. Not very elegant, but it works. I can open issue/PR if you think that's a way forward. BTW, not sure why but at least on my system (now 3.9.7) the new V check code isn't needed.
Edit: just to show:
output:
|
@psobolewskiPhD I'd definitely open a new issue and report/resume this discussion there. |
@psobolewskiPhD Re: the need of the "V" patch. I suspect eventually the Python teams would integrate/had integrated the patch within |
I get the following error when using darkdetect from the terminal:
This happens when using any method, i.e.,
isDark
,isLight
, ortheme
. For information, I'm running macOS Big Sur 11.4 (20F71).The text was updated successfully, but these errors were encountered: