Compare commits
3 Commits
28ea8e787a
...
35b0c4bef0
Author | SHA1 | Date |
---|---|---|
Tyler Goodlet | 35b0c4bef0 | |
Tyler Goodlet | c4496f21fc | |
Tyler Goodlet | 7e0e627921 |
|
@ -69,10 +69,10 @@ def _unwrap_msg(
|
|||
__tracebackhide__ = True
|
||||
try:
|
||||
return msg['return']
|
||||
except KeyError:
|
||||
except KeyError as ke:
|
||||
# internal error should never get here
|
||||
assert msg.get('cid'), "Received internal error at portal?"
|
||||
raise unpack_error(msg, channel) from None
|
||||
raise unpack_error(msg, channel) from ke
|
||||
|
||||
|
||||
class Portal:
|
||||
|
|
|
@ -19,22 +19,13 @@ Sugary patterns for trio + tractor designs.
|
|||
|
||||
'''
|
||||
from ._mngrs import (
|
||||
gather_contexts,
|
||||
maybe_open_context,
|
||||
maybe_open_nursery,
|
||||
gather_contexts as gather_contexts,
|
||||
maybe_open_context as maybe_open_context,
|
||||
maybe_open_nursery as maybe_open_nursery,
|
||||
)
|
||||
from ._broadcast import (
|
||||
broadcast_receiver,
|
||||
BroadcastReceiver,
|
||||
Lagged,
|
||||
AsyncReceiver as AsyncReceiver,
|
||||
broadcast_receiver as broadcast_receiver,
|
||||
BroadcastReceiver as BroadcastReceiver,
|
||||
Lagged as Lagged,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
'gather_contexts',
|
||||
'broadcast_receiver',
|
||||
'BroadcastReceiver',
|
||||
'Lagged',
|
||||
'maybe_open_context',
|
||||
'maybe_open_nursery',
|
||||
]
|
||||
|
|
|
@ -225,6 +225,7 @@ async def maybe_open_context(
|
|||
|
||||
# yielded output
|
||||
yielded: Any = None
|
||||
lock_registered: bool = False
|
||||
|
||||
# Lock resource acquisition around task racing / ``trio``'s
|
||||
# scheduler protocol.
|
||||
|
@ -232,6 +233,7 @@ async def maybe_open_context(
|
|||
# to allow re-entrant use cases where one `maybe_open_context()`
|
||||
# wrapped factor may want to call into another.
|
||||
lock = _Cache.locks.setdefault(fid, trio.Lock())
|
||||
lock_registered: bool = True
|
||||
await lock.acquire()
|
||||
|
||||
# XXX: one singleton nursery per actor and we want to
|
||||
|
@ -291,4 +293,9 @@ async def maybe_open_context(
|
|||
_, no_more_users = entry
|
||||
no_more_users.set()
|
||||
|
||||
_Cache.locks.pop(fid)
|
||||
if lock_registered:
|
||||
maybe_lock = _Cache.locks.pop(fid, None)
|
||||
if maybe_lock is None:
|
||||
log.error(
|
||||
f'Resource lock for {fid} ALREADY POPPED?'
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue