-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathborrows.py
More file actions
23 lines (19 loc) · 731 Bytes
/
Copy pathborrows.py
File metadata and controls
23 lines (19 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import TYPE_CHECKING, Dict, NamedTuple, Optional, List
import traceback
from weakref import WeakSet
if TYPE_CHECKING:
from .stream import Stream
class Borrow(NamedTuple):
id: int
used: bool
frames: List[traceback.FrameSummary]
# we have one Borrows entry for each storage of live controller Tensors
class Borrows:
def __init__(self, origin_stream: 'Stream'):
self.origin_stream = origin_stream
# who can write to this storage?
self.writing_stream: Optional['Stream'] = origin_stream
# what Tensor aliases exist for this storage
self.aliases = WeakSet()
# what active borrows of this storage exist?
self.active: Dict['Stream', Borrow] = {}