Exemplo n.º 1
0
    async def read(self, *args, **kwargs):
        """Request a fresh reading, wait for it, return it and stash it.

        The most recent reading is always available in the ``last_reading``
        attribute.
        """
        command = self.channel.read(*args, **kwargs)
        # Stash the ioid to match the response to the request.
        ioid = command.ioid
        # TODO this could be implemented as a concurrent.Future and use
        #      curio.traps._future_wait. A Future is really what we want here,
        #      but it doesn't seem like curio provides such a primitive for us
        ioid = command.ioid
        event = curio.Event()
        self.circuit.ioids[ioid] = event
        await self.circuit.send(command)
        await event.wait()

        reading = self.circuit.ioid_data.pop(ioid)
        if isinstance(reading, ca.ReadNotifyResponse):
            self.last_reading = reading
            return self.last_reading
        else:
            raise ChannelReadError(str(reading))
Exemplo n.º 2
0
"""
curio_demo_10.py - Curio tutorial.

(from https://curio.readthedocs.io/en/latest/tutorial.html)

Provide emergency stopping of tasks.
"""

import curio
import signal

# an event object for tracking permission from the parent
start_evt = curio.Event()


async def countdown(n):
    """
    A simple countdown timer based on the curio sleep rather than standard.

    :param n: number of seconds to sleep
    :return:
    """
    while n > 0:
        print('T-minus', n)
        await curio.sleep(1)
        n -= 1


async def friend(name):
    """
    Create a friend task to help build the Millennium Falcon.
Exemplo n.º 3
0
 def __init__(self):
     self._evt = curio.Event()
Exemplo n.º 4
0
 def __init__(self):
     self._exception = self.__no_value
     self._value = self.__no_value
     self._event = curio.Event()
Exemplo n.º 5
0
	def __init__(self, value):
		self._value = value
		self._event = curio.Event()
Exemplo n.º 6
0
 def __init__(self, env):
     self.env = env
     self.session = None
     self._apiVersion_cache = {}
     self._kind_cache = {}
     self.healthy = curio.Event()
Exemplo n.º 7
0
 def __init__(self, cache, api, kind, **kw):
     self.warm = MagicMock(wraps=curio.Event())