How to use the trio.Lock 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 HyperionGray / trio-chrome-devtools-protocol / trio_cdp / __init__.py View on Github external
def __init__(self, ws, session_id, target_id):
        '''
        Constructor.

        :param trio_websocket.WebSocketConnection ws:
        :param cdp.target.SessionID session_id:
        :param cdp.target.TargetID target_id:
        '''
        super().__init__(ws, session_id, target_id)

        self._dom_enable_count = 0
        self._dom_enable_lock = trio.Lock()
        self._page_enable_count = 0
        self._page_enable_lock = trio.Lock()
github ethereum / lahja / lahja / trio / endpoint.py View on Github external
def __init__(self, name: str):
        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()
github pgjones / hypercorn / hypercorn / trio / h2.py View on Github external
def __init__(
        self,
        app: ASGIFramework,
        config: Config,
        stream: trio.abc.Stream,
        *,
        upgrade_request: Optional[h11.Request] = None,
        received_data: Optional[bytes] = None,
    ) -> None:
        super().__init__(stream, "h2")
        self.app = app
        self.config = config

        self.streams: Dict[int, H2AsyncStream] = {}
        self.flow_control: Dict[int, trio.Event] = {}
        self.send_lock = trio.Lock()
        self.upgrade_request = upgrade_request
        self.received_data = received_data

        self.connection = h2.connection.H2Connection(
            config=h2.config.H2Configuration(client_side=False, header_encoding=None)
        )
        self.connection.DEFAULT_MAX_INBOUND_FRAME_SIZE = config.h2_max_inbound_frame_size
        self.connection.local_settings = h2.settings.Settings(
            client=False,
            initial_values={
                h2.settings.SettingCodes.MAX_CONCURRENT_STREAMS: config.h2_max_concurrent_streams,
                h2.settings.SettingCodes.MAX_HEADER_LIST_SIZE: config.h2_max_header_list_size,
                h2.settings.SettingCodes.ENABLE_CONNECT_PROTOCOL: 1,
            },
github syncrypt / client / syncrypt / app / vault.py View on Github external
def __init__(self, app, vault, update_on_idle=False):
        self.app = app
        self.vault = vault
        self.lock = trio.Lock()
        self.ready = False
        self.nursery = None  # type: Optional[Nursery]
        self.update_on_idle = update_on_idle
        self.logger = VaultLoggerAdapter(self.vault, logging.getLogger(__name__))
        send_channel, receive_channel = trio.open_memory_channel(128) # type: Tuple[trio.abc.SendChannel, trio.abc.ReceiveChannel]
        self.file_changes_send_channel = send_channel # type: trio.abc.SendChannel
        self.file_changes_receive_channel = receive_channel # type: trio.abc.ReceiveChannel
        self.cancel_scope = trio.CancelScope()
github python-trio / trio-amqp / trio_amqp / channel.py View on Github external
def __init__(self, protocol, channel_id):
        self.protocol = protocol
        self.channel_id = channel_id
        self.consumer_queues = {}
        self.consumer_callbacks = {}
        self.response_future = None
        self.close_event = trio.Event()
        self.cancelled_consumers = set()
        self.last_consumer_tag = None
        self.publisher_confirms = False

        self.delivery_tag_iter = None
        # counting iterator, used for mapping delivered messages
        # to publisher confirms

        self._write_lock = trio.Lock()

        self._futures = {}
        self._ctag_events = {}

        self._chan_send = None
        self._chan_receive = None
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 HyperionGray / trio-chrome-devtools-protocol / trio_cdp / __init__.py View on Github external
def __init__(self, ws, session_id, target_id):
        '''
        Constructor.

        :param trio_websocket.WebSocketConnection ws:
        :param cdp.target.SessionID session_id:
        :param cdp.target.TargetID target_id:
        '''
        super().__init__(ws, session_id, target_id)

        self._dom_enable_count = 0
        self._dom_enable_lock = trio.Lock()
        self._page_enable_count = 0
        self._page_enable_lock = trio.Lock()
github ethereum / lahja / lahja / trio / endpoint.py View on Github external
def __init__(
        self,
        local_name: str,
        conn: ConnectionAPI,
        subscriptions_changed: ConditionAPI,
        new_msg_func: Callable[[Broadcast], Awaitable[Any]],
    ) -> None:
        super().__init__(local_name, conn, new_msg_func)

        self._notify_lock = trio.Lock()  # type: ignore

        self._received_response = trio.Condition()  # type: ignore
        self._received_subscription = trio.Condition()  # type: ignore

        self._running = trio.Event()  # type: ignore
        self._stopped = trio.Event()  # type: ignore

        self._received_subscription = subscriptions_changed

        self._subscriptions_initialized = trio.Event()  # type: ignore

        self._running = trio.Event()  # type: ignore
        self._stopped = trio.Event()  # type: ignore
        self._ready = trio.Event()  # type: ignore