from PyMacAdmin.crankd.handlers import BaseHandler
seems that crankd is no longer part of the module?
So I was looking at the func get_callable_from_string and realized
that the callable would have to be resolvable from the python path,
not a callable I define in my running code.
I then looked a little further into how I could use crankd
notifications inside a python script. The three technologies that
crankd seems to expose are represented by:
FSEventStreamScheduleWithRunLoop
SCDynamicStoreCreateRunLoopSource
NSWorkspace.sharedWorkspace().notificationCenter()
I think there is opportunity to factor these out into 3 classes in the
PyMacAdmin module (ie):
FSEventListener
SystemConfigurationListener
WorkspaceListener
each of these would have an add_event(event, callback) method
each would have start_listening and stop_listening methods, and each
would try to clean up after itself in a __del__ method
crankd.py would then instantiate these, read the config, call the
commands etc with no change to its usage.
One thing that wasn't clear was whether the timer_callback kludge
would be needed in every case where a SystemConfigurationListener
would be use, or if that could be encapsulated.
-Preston
seems that crankd is no longer part of the module?
One thing that wasn't clear was whether the timer_callback kludge
would be needed in every case where a SystemConfigurationListener
would be use, or if that could be encapsulated.
When configuring the run loop for a long-lived thread, it is better to add at least one input source to receive messages. Although you can enter the run loop with only a timer attached, once the timer fires, it is typically invalidated, which would then cause the run loop to exit. Attaching a repeating timer could keep the run loop running over a longer period of time, but would involve firing the timer periodically to wake your thread, which is effectively another form of polling. By contrast, an input source waits for an event to happen, keeping your thread asleep until it does.