How to use the pykka.Timeout function in pykka

To help you get started, we’ve selected a few pykka examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jodal / pykka / tests / test_ref.py View on Github external
def test_ask_can_timeout_if_blocked_too_long(actor_ref):
    with pytest.raises(Timeout):
        actor_ref.ask({'command': 'ping'}, timeout=0)
github jodal / pykka / tests / test_future.py View on Github external
def test_filter_preserves_the_timeout_kwarg(future):
    filtered = future.filter(lambda x: x > 10)

    with pytest.raises(Timeout):
        filtered.get(timeout=0)
github tkem / mopidy-dleyna / mopidy_dleyna / util.py View on Github external
import logging
import time

import pykka

logger = logging.getLogger(__name__)


class Future(pykka.ThreadingFuture):

    Timeout = pykka.Timeout

    @classmethod
    def exception(cls, exc=None):
        future = cls()
        future.set_exception((type(exc), exc, None))
        return future

    @classmethod
    def fromdbus(cls, func, *args, **kwargs):
        method = getattr(func, "_method_name", "")
        logger.debug("Calling D-Bus method %s%s", method, args)
        future = cls()
        start = time.time()

        def reply(*args):
            logger.debug("%s reply after %.3fs", method, time.time() - start)
github lostcontrol / poupool / controller / filtration.py View on Github external
def __actor_halt(self, name):
        actor = self.get_actor(name)
        try:
            # We have seen situation where this creates a deadlock. We add a timeout so that we
            # eventually return from the get() and force the halt transition.
            if not actor.is_halt().get(timeout=1):
                actor.halt.defer()
        except pykka.Timeout:
            actor.halt.defer()
github autodesk-cloud / ochothon / images / portal / resources / toolset / toolset / io.py View on Github external
try:
        latch = pykka.ThreadingFuture()
        proxy.tell(
            {
                'request': 'execute',
                'latch': latch,
                'function': func
            })
        Event()
        out = latch.get(timeout=timeout)
        if isinstance(out, Exception):
            raise out

        return out

    except Timeout:

        assert 0, 'request timeout'
github mopidy / mopidy / mopidy / backends / spotify / library.py View on Github external
translator.to_mopidy_artist(a) for a in results.artists()],
                tracks=[
                    translator.to_mopidy_track(t) for t in results.tracks()])
            future.set(search_result)

        if not self.backend.spotify.connected.is_set():
            logger.debug('Not connected: Spotify search cancelled')
            return SearchResult(uri='spotify:search')

        self.backend.spotify.session.search(
            spotify_query, callback,
            album_count=200, artist_count=200, track_count=200)

        try:
            return future.get(timeout=self._timeout)
        except pykka.Timeout:
            logger.debug(
                'Timeout: Spotify search did not return in %ds', self._timeout)
            return SearchResult(uri='spotify:search')
github autodesk-cloud / ochopod / sdk / ochopod / core / core.py View on Github external
# - if the termination trigger is set, abort immediately
        #
        if self.force_reset or self.terminate:
            raise Aborted('resetting')

        #
        # - spin-lock on the controller latch
        # - any catastrophic plug failure will be trapped that way
        #
        try:
            Event()
            out = data.latch.get(SAMPLING)
            if isinstance(out, Exception):
                raise out

        except Timeout:
            pass

        return 'lock', data, 0
github autodesk-cloud / ochopod / ochopod / core / fsm.py View on Github external
:type actor_ref: :class:`pykka.ActorRef`
    :param actor_ref: a pykka actor reference
    :type timeout: float
    :param timeout: optional timeout in seconds
    """
    try:
        if not actor_ref:
            return

        latch = ThreadingFuture()
        actor_ref.tell({'request': 'shutdown', 'latch': latch})
        Event()
        latch.get(timeout=timeout)

    except Timeout:
        pass

    except ActorDeadError:
        pass
github jodal / pykka / pykka / _threading.py View on Github external
def get(self, timeout=None):
        try:
            return super(ThreadingFuture, self).get(timeout=timeout)
        except NotImplementedError:
            pass

        try:
            if self._data is None:
                self._data = self._queue.get(True, timeout)
            if 'exc_info' in self._data:
                _compat.reraise(*self._data['exc_info'])
            else:
                return self._data['value']
        except _compat.queue.Empty:
            raise Timeout('{} seconds'.format(timeout))
github tkem / mopidy-internetarchive / mopidy_internetarchive / playlists.py View on Github external
def stop(self):
        if self.bookmarks:
            logger.debug('Stopping %s', self.bookmarks)
            try:
                self.bookmarks.stop(timeout=1)
            except pykka.Timeout:
                # bookmarks actor may be waiting on backend
                pykka.ActorRegistry.unregister(self.bookmarks)