How to use the trio.Condition function in trio

To help you get started, we’ve selected a few trio 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 agronholm / anyio / src / anyio / _backends / _trio.py View on Github external
def __init__(self, lock: Optional[trio.Lock] = None):
        self._cond = trio.Condition(lock=lock)
github caproto / caproto / caproto / trio / client.py View on Github external
def __init__(self, circuit, *, nursery):
        self.circuit = circuit  # a caproto.VirtualCircuit
        self.log = self.circuit.log
        self.nursery = nursery
        self.channels = {}  # map cid to Channel
        self.ioids = {}  # map ioid to Channel
        self.ioid_data = {}  # map ioid to server response
        self.subscriptionids = {}  # map subscriptionid to Channel
        self.connected = True
        self.socket = None
        self.command_chan = open_memory_channel(1000)
        self.new_command_condition = trio.Condition()
        self._socket_lock = trio.Lock()
github caproto / caproto / caproto / trio / server.py View on Github external
def __init__(self, circuit, client, context):
        super().__init__(circuit, client, context)
        self._raw_lock = trio.Lock()
        self.nursery = context.nursery
        self.QueueFull = trio.WouldBlock

        self.command_chan = open_memory_channel(ca.MAX_COMMAND_BACKLOG)

        # For compatibility with server common:
        self.command_queue = self.command_chan.send

        self.new_command_condition = trio.Condition()
        self.subscription_chan = open_memory_channel(ca.MAX_TOTAL_SUBSCRIPTION_BACKLOG)

        # For compatibility with server common:
        self.subscription_queue = self.subscription_chan.send

        self.write_event = Event()
        self.events_on = trio.Event()
github caproto / caproto / caproto / trio / client.py View on Github external
def __init__(self, *, nursery):
        self.nursery = nursery
        self.broadcaster = ca.Broadcaster(our_role=ca.CLIENT)
        self.log = self.broadcaster.log
        self.command_chan = open_memory_channel(1000)
        self.broadcaster_command_condition = trio.Condition()
        self._cleanup_condition = trio.Condition()
        self._cleanup_event = trio.Event()

        # UDP socket broadcasting to CA servers
        self.udp_sock = None
        self.registered = False  # refers to RepeaterRegisterRequest
        self.unanswered_searches = {}  # map search id (cid) to name
        self.search_results = {}  # map name to address
        self.new_id = ThreadsafeCounter(
            dont_clash_with=self.unanswered_searches)

        self.environ = get_environment_variables()
        self.ca_server_port = self.environ['EPICS_CA_SERVER_PORT']
github ethereum / lahja / lahja / trio / endpoint.py View on Github external
super().__init__(name)

        self._running = trio.Event()
        self._stopped = trio.Event()

        # Temporary storage for SendChannels used in the `stream` API.  Uses a
        # `WeakSet` to automate cleanup.
        self._stream_channels = collections.defaultdict(set)
        self._pending_requests = {}
        self._sync_handlers = collections.defaultdict(list)
        self._async_handlers = collections.defaultdict(list)

        self._run_lock = trio.Lock()

        # Signal when a new remote connection is established
        self._remote_connections_changed = trio.Condition()  # type: ignore

        # Signal when at least one remote has had a subscription change.
        self._remote_subscriptions_changed = trio.Condition()  # type: ignore

        # events used to signal that the endpoint has fully booted up.
        self._message_processing_loop_running = trio.Event()
        self._connection_loop_running = trio.Event()
        self._process_broadcasts_running = trio.Event()

        # internal signal that local subscriptions have changed.
        self._subscriptions_changed = trio.Event()

        self._socket_bound = trio.Event()
        self._server_stopped = trio.Event()
github caproto / caproto / caproto / trio / client.py View on Github external
def __init__(self, *, nursery):
        self.nursery = nursery
        self.broadcaster = ca.Broadcaster(our_role=ca.CLIENT)
        self.log = self.broadcaster.log
        self.command_chan = open_memory_channel(1000)
        self.broadcaster_command_condition = trio.Condition()
        self._cleanup_condition = trio.Condition()
        self._cleanup_event = trio.Event()

        # UDP socket broadcasting to CA servers
        self.udp_sock = None
        self.registered = False  # refers to RepeaterRegisterRequest
        self.unanswered_searches = {}  # map search id (cid) to name
        self.search_results = {}  # map name to address
        self.new_id = ThreadsafeCounter(
            dont_clash_with=self.unanswered_searches)

        self.environ = get_environment_variables()
        self.ca_server_port = self.environ['EPICS_CA_SERVER_PORT']
github s3ql / s3ql / src / s3ql / block_cache.py View on Github external
def __init__(self, backend_pool, db, cachedir, max_size, max_entries=768):
        log.debug('Initializing')

        self.path = cachedir
        self.db = db
        self.backend_pool = backend_pool
        self.cache = CacheDict(max_size, max_entries)
        self.mlock = MultiLock()
        self.in_transit = set()
        self.upload_threads = []
        self.removal_threads = []
        self.transfer_completed = trio.Condition()

        # Will be initialized once threads are available
        self.to_upload = None
        self.to_remove = None

        if os.path.exists(self.path):
            self.load_cache()
            log.info('Loaded %d entries from cache', len(self.cache))
        else:
            os.mkdir(self.path)

        # Initialized fromt the outside to prevent cyclic dependency
        self.fs = None
github s3ql / s3ql / src / s3ql / multi_lock.py View on Github external
def __init__(self):
        self.locked_keys = set()
        self.cond = trio.Condition()