!OqDVTrmPstKzivLwZW:gitter.im

python-trio/general

776 Members
Discussion of Trio, a friendly Python library for async concurrency and I/O17 Servers

Load older messages


SenderMessageTime
19 Jun 2024
@goodboy:matrix.orglord_fomo *

so then the user API would be something like:

@singleton
async def open_service_mngr(
    **init_kwargs,
) -> ServiceMngr:
    '''
    Note: this function body is invoked IFF there is NO singleton instance already
    in the current proc's memory.

    '''
    # setup
    yield ServiceMngr(**init_kwargs)
    # teardown
19:29:31
@goodboy:matrix.orglord_fomo *

so then the user API would be something like:

@singleton
def open_service_mngr(
    **init_kwargs,
) -> ServiceMngr:
    '''
    Note: this function body is invoked IFF there is NO singleton instance already
    in the current proc's memory.

    '''
    # setup
    yield ServiceMngr(**init_kwargs)
    # teardown
19:32:54
@goodboy:matrix.orglord_fomo *
@cm
def open_service_mngr(
    *,
    _singleton: list[ServiceMngr|None] = [None],
    **init_kwargs,

) -> ServiceMngr:
    '''
    Open a multi-subactor-as-service-daemon tree supervisor.

    The delivered `ServiceMngr` is a singleton instance for each
    actor-process and is allocated on first open and never
    de-allocated unless explicitly deleted by al call to
    `del_service_mngr()`.

    '''
    mngr: ServiceMngr|None
    if (mngr := _singleton[0]) is None:
        log.info('Allocating a new service mngr!')
        mngr = _singleton[0] = ServiceMngr(**init_kwargs)
    else:
        log.info(
            'Using extant service mngr!\n\n'
            f'{mngr!r}\n'  # it has a nice `.__repr__()` of services state
        )

    with mngr:
        yield mngr
19:33:11
@goodboy:matrix.orglord_fomo hmm, and i'd prolly implement it using wrapt i'd wager 19:33:40
@goodboy:matrix.orglord_fomohmm, and then the final thing would be (implicitly) exposing a deletion API, prolly as a method on the factory19:37:19
@goodboy:matrix.orglord_fomo* hmm, and then the final thing would be (implicitly) exposing a deletion API, prolly as a method on the factory?19:37:22
@goodboy:matrix.orglord_fomoor maybe via monkey-patch to the instance?19:37:31
@goodboy:matrix.orglord_fomokinda like the former better even though unconventional19:37:40
@goodboy:matrix.orglord_fomo something like .open_service_mngr.delete()/.dealloc() kinda thing. 19:38:15
@goodboy:matrix.orglord_fomo which would remove the factory's _singleton: list ref and then all others in use would obvi be handed by gc 19:39:05
@goodboy:matrix.orglord_fomo
19:48:52
@goodboy:matrix.orglord_fomo totes unrelated, first time i'm trying to use the pydoc -k <patt> search, and wow does it not behave well if you ctl-c the scan 😂 19:49:17
@goodboy:matrix.orglord_fomosome SC there could definitely help i bet19:49:32
@goodboy:matrix.orglord_fomo
21:19:50
@goodboy:matrix.orglord_fomo any reason it wouldn't be handy to add a CancelScope._cancel_status.first_cancel_caller: Task attr? 21:20:21
@goodboy:matrix.orglord_fomosuch that the first caller task is always tracked21:20:37
@goodboy:matrix.orglord_fomoi often have to manually come up with something for this when tracing unexpected cancels21:21:03
@oremanj-5abea8c4d73408ce4f93d0be:gitter.imoremanj (Joshua Oreman)because it’s an internal type that is designed for trio’s needs, not yours, and trio has no need for it21:21:19
@oremanj-5abea8c4d73408ce4f93d0be:gitter.imoremanj (Joshua Oreman)* because it’s an internal type that is designed for trio’s needs, not yours, and trio has no need for this attribute21:21:27
@oremanj-5abea8c4d73408ce4f93d0be:gitter.imoremanj (Joshua Oreman)and including anything unnecessary makes this core primitive be slower and use more memory21:21:56
@goodboy:matrix.orglord_fomofair, but what about as a tooling thing?21:22:14
@goodboy:matrix.orglord_fomolike could i do something similar via an instrument?21:22:36
@oremanj-5abea8c4d73408ce4f93d0be:gitter.imoremanj (Joshua Oreman)the “first cancel caller” is not even well-defined, because you can call cancel() from outside a task at all - in an abort_fn, from a thread, from the host loop in a guest mode scenario21:22:58
@goodboy:matrix.orglord_fomo right, so really whoever is the caller first we can find some kind of "thread" property from it no? 21:23:31
@goodboy:matrix.orglord_fomo i have to do with tractor's debugger as it is 21:23:43
@teamspen210-5734b2c8c43b8c6019728f66:gitter.imTeamSpen210 (Spencer Brown) If you want to inspect it for debugging, you could just monkeypatch CancelScope.cancel()... 21:24:24
@goodboy:matrix.orglord_fomosure, not as ideal i guess.21:24:57
@goodboy:matrix.orglord_fomo

i mean, the current impl is already short circuited:

    @enable_ki_protection
    def cancel(self) -> None:
        """Cancels this scope immediately.

        This method is idempotent, i.e., if the scope was already
        cancelled then this method silently does nothing.
        """
        if self._cancel_called:
            return
        with self._might_change_registered_deadline():
            self._cancel_called = True
        if self._cancel_status is not None:
            self._cancel_status.recalculate()
21:26:16
@hardy_tom:matrix.org@hardy_tom:matrix.orgRedacted or Malformed Event23:57:41
@hardy_tom:matrix.org@hardy_tom:matrix.org left the room.23:58:59

There are no newer messages yet.


Back to Room ListRoom Version: 6