Code Monkey home page Code Monkey logo

Comments (6)

michelcrypt4d4mus avatar michelcrypt4d4mus commented on June 26, 2024

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.

michelcrypt4d4mus avatar michelcrypt4d4mus commented on June 26, 2024

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.

Jorricks avatar Jorricks commented on June 26, 2024

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.

Hi @michelcrypt4d4mus,

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.

michelcrypt4d4mus avatar michelcrypt4d4mus commented on June 26, 2024

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.

michelcrypt4d4mus avatar michelcrypt4d4mus commented on June 26, 2024

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.

michelcrypt4d4mus avatar michelcrypt4d4mus commented on June 26, 2024

closing this because it's actually an issue with twisted itself

from macos-notifications.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.