Comments (6)
I just tried using the package from a daemon running in user space (~/Library/LaunchAgents
, not /Library/LaunchDaemons
) and ran into the same issue.
I was somewhat surprised to see that a shell call to osascript
was able to work when running a daemon in user space (running osascript
as a root:wheel
daemon does not work). e.g. this works:
import os
command = f'''
osascript -e 'display notification "This is a notification" with title "Notifying"'
'''
os.system(command)
but this does not:
from mac_notifications import client
client.create_notification(title="This is a notification", subtitle="Notifying")
The error is the same as when I attempted to call create_notification()
from the root daemon (builtins.ValueError: bad value(s) in fds_to_keep
), here's the full stack trace:
File "/Users/uzor/workspace/fork_canary/env/lib/python3.12/site-packages/opencanary/modules/__init__.py", line 207, in send_notification
client.create_notification(
File "/Users/uzor/workspace/fork_canary/env/lib/python3.12/site-packages/mac_notifications/client.py", line 66, in create_notification
return get_notification_manager().create_notification(notification_config)
File "/Users/uzor/workspace/fork_canary/env/lib/python3.12/site-packages/mac_notifications/client.py", line 21, in get_notification_manager
return NotificationManager()
File "/Users/uzor/workspace/fork_canary/env/lib/python3.12/site-packages/mac_notifications/singleton.py", line 17, in __call__
instance = super().__call__(*args, **kwargs)
File "/Users/uzor/workspace/fork_canary/env/lib/python3.12/site-packages/mac_notifications/manager.py", line 51, in __init__
self._callback_queue: SimpleQueue = SimpleQueue()
File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/context.py", line 113, in SimpleQueue
return SimpleQueue(ctx=self.get_context())
File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/queues.py", line 363, in __init__
self._rlock = ctx.Lock()
File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/context.py", line 68, in Lock
return Lock(ctx=self.get_context())
File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/synchronize.py", line 169, in __init__
SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)
File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/synchronize.py", line 80, in __init__
register(self._semlock.name, "semaphore")
File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/resource_tracker.py", line 174, in register
self._send('REGISTER', name, rtype)
File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/resource_tracker.py", line 182, in _send
self.ensure_running()
File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/resource_tracker.py", line 148, in ensure_running
pid = util.spawnv_passfds(exe, args, fds_to_pass)
File "/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/multiprocessing/util.py", line 456, in spawnv_passfds
return _posixsubprocess.fork_exec(
builtins.ValueError: bad value(s) in fds_to_keep
from macos-notifications.
This seems to happen not just when run by launchctl
because i ran into the same error running via a twistd
server process. Seems to fail on instantiating SimpleQueue
, this line:
self._callback_queue: SimpleQueue = SimpleQueue()
I found that if I just disabled all of the multiprocessing
stuff I was able to make your package work without issue in the context I need.
from macos-notifications.
This seems to happen not just when run by
launchctl
because i ran into the same error running via atwistd
server process. Seems to fail on instantiatingSimpleQueue
, this line:self._callback_queue: SimpleQueue = SimpleQueue()
I found that if I just disabled all of the
multiprocessing
stuff I was able to make your package work without issue in the context I need.
First of all, thanks for raising the issue and using the package. Nice to see you found a solution.
Do you think we could make this an option in the package where you specify whether you want an asynchronous flow or the flow without any multiprocessing?
from macos-notifications.
Yes, that's more or less exactly what I did, albeit in a very janky af fashion. It's your package; can be configured however you want. Could just be an argument to create_notification()
maybe?
from macos-notifications.
So this is pretty weird - i found that if i instantiate a SimpleQueue()
object in my application before any calls are made to macos_notifications
then the problem goes away.
my application is based on twistd
/ Twisted which i know does some of its own thread management so i'm guessing it's somehow related to that. either way it's almost certainly a bug somewhere - not in this package, most likely in Twisted. I found this 5 year old issue where someone running a twisted based web app ran into the same error but there wasn't much in the way of resolution.
interestingly a new problem crops up when i do that in the form of a warning:
python3.12/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 2 leaked semaphore objects to clean up at shutdown
which strikes me as almost certainly a more benign version of the error that caused the crash, given that the "fd" fds_to_keep
in the original error message is referring to file descriptor semaphores for IPC. actual error is generated here in the cython code.
from macos-notifications.
closing this because it's actually an issue with twisted itself
from macos-notifications.
Related Issues (20)
- Examples with callbacks always timeout HOT 2
- macos-notifications fails to install on CPython 3.11 HOT 3
- macos-notifications 0.1.5 does not give a notification on python 3.10 HOT 1
- Installation conflicts with latest version of PyObjC HOT 1
- Python3.7 install of macos-notifications does not show a notification HOT 2
- AttributeError: 'NoneType' object has no attribute 'setDelegate_' HOT 7
- RuntimeError involving freeze_support() HOT 4
- Python's icon HOT 2
- Issue with freeze support on Python 3.11 HOT 5
- Library not working in frozen application (e.g. with PyInstaller) HOT 5
- notification not shown in macos 13 with python 3.11 HOT 1
- There is no API to delete notifications HOT 1
- Missing from the documentation? How to create a persistent notification HOT 3
- mac_notifications-utilizing process never exits HOT 1
- One program, two notifications: one notification seems to dismiss the other HOT 3
- Doesn't support threading HOT 2
- The library amends process logging HOT 1
- Link in documentation with instructions on enabling notifications points to a wrong location HOT 1
- Add optional User Notification support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from macos-notifications.