SubscriptionContext
class¶
Bases: ABC
, Generic[_SourceType, _SubscriberType]
An abstract base class for subscription context managers.
Notes:
-
This class is designed to establish a context block for a step-by-step definition of an object that will later be subscribed to a specified source.
-
Upon exiting the context, the defined object will be automatically subscribed.
-
Through the
unpack()
method, this class not only returns the source object and its subscriber but also handles the release and cleanup of associated resources. -
This subscription context can be
stateful
, retaining references to thesource
object andsubscriber
, orstateless
, which clears the context upon exiting the subscription block.
Source code in pyventus/core/subscriptions/subscription_context.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
Functions¶
__init__
¶
Initialize an instance of SubscriptionContext
.
PARAMETER | DESCRIPTION |
---|---|
source
|
The source to which the subscription is performed.
TYPE:
|
is_stateful
|
A flag indicating whether the context preserves its state (stateful) or not (stateless) after exiting the subscription context. If
TYPE:
|
Source code in pyventus/core/subscriptions/subscription_context.py
unpack
¶
Unpack and retrieve the source object and its associated subscriber.
This method returns a tuple containing the source object and its subscriber, while also handling the cleanup of associated resources to prevent memory leaks. After retrieving the objects, it deletes internal references to the source and subscriber to ensure they are no longer retained.
RETURNS | DESCRIPTION |
---|---|
tuple[_SourceType | None, _SubscriberType | None]
|
A tuple of the form (source, subscriber). Both may be |
RAISES | DESCRIPTION |
---|---|
PyventusException
|
If this method is called before or during the subscription context, indicating that the resources are not yet available for unpacking. |
Source code in pyventus/core/subscriptions/subscription_context.py
__enter__
¶
Enter the subscription context block.
This method facilitates the progressive definition of an object that will later be subscribed to the specified source.
RETURNS | DESCRIPTION |
---|---|
Self
|
The subscription context manager. |
Source code in pyventus/core/subscriptions/subscription_context.py
__exit__
¶
__exit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None
Exit the subscription context block.
This method subscribes the defined object to the specified source, and performs any necessary cleanup.
PARAMETER | DESCRIPTION |
---|---|
exc_type
|
The type of the raised exception, if any.
TYPE:
|
exc_val
|
The raised exception object, if any.
TYPE:
|
exc_tb
|
The traceback information, if any.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |