def start_core(self, config, mixer, backends, audio): logger.info("Starting Mopidy core") core = Core.start(config=config, mixer=mixer, backends=backends, audio=audio).proxy() call = ProxyCall(attr_path=["_setup"], args=[], kwargs={}) core.actor_ref.ask(call, block=True) return core
def _on_about_to_finish_callback(self): """Callback that performs a blocking actor call to the real callback. This is passed to audio, which is allowed to call this code from the audio thread. We pass execution into the core actor to ensure that there is no unsafe access of state in core. This must block until we get a response. """ self.core.actor_ref.ask( ProxyCall( attr_path=["playback", "_on_about_to_finish"], args=[], kwargs={}, ))
def send(cls, event, **kwargs): listeners = pykka.ActorRegistry.get_by_class(cls) logger.debug("Sending %s to %s: %s", event, cls.__name__, kwargs) for listener in listeners: # Save time by calling methods on Pykka actor without creating a # throwaway actor proxy. # # Because we use `.tell()` there is no return channel for any errors, # so Pykka logs them immediately. The alternative would be to use # `.ask()` and `.get()` the returned futures to block for the listeners # to react and return their exceptions to us. Since emitting events in # practise is making calls upwards in the stack, blocking here would # quickly deadlock. listener.tell( ProxyCall(attr_path=["on_event"], args=[event], kwargs=kwargs,) )
def stop_core(self, core): logger.info("Stopping Mopidy core") if core: call = ProxyCall(attr_path=["_teardown"], args=[], kwargs={}) core.actor_ref.ask(call, block=True) process.stop_actors_by_class(Core)
def save_state(self): call = ProxyCall(attr_path=["_save_state"], args=[], kwargs={}) self.core.actor_ref.ask(call, block=True)
@pytest.mark.parametrize( 'old_format, new_format', [ ({ 'command': 'pykka_stop' }, _ActorStop()), ( { 'command': 'pykka_call', 'attr_path': ['nested', 'method'], 'args': [1], 'kwargs': { 'a': 'b' }, }, ProxyCall( attr_path=['nested', 'method'], args=[1], kwargs={'a': 'b'}), ), ( { 'command': 'pykka_getattr', 'attr_path': ['nested', 'attr'] }, ProxyGetAttr(attr_path=['nested', 'attr']), ), ( { 'command': 'pykka_setattr', 'attr_path': ['nested', 'attr'], 'value': 'abcdef', }, ProxySetAttr(attr_path=['nested', 'attr'], value='abcdef'),