33
44"""Management of configuration."""
55
6- import asyncio
76import logging
87import pathlib
98from collections .abc import Mapping , Sequence
@@ -37,7 +36,6 @@ def __init__( # pylint: disable=too-many-arguments
3736 logging_config_key : str | Sequence [str ] | None = "logging" ,
3837 name : str | None = None ,
3938 polling_interval : timedelta = timedelta (seconds = 5 ),
40- wait_for_first_timeout : timedelta = timedelta (seconds = 5 ),
4139 ) -> None :
4240 """Initialize this config manager.
4341
@@ -58,10 +56,6 @@ def __init__( # pylint: disable=too-many-arguments
5856 be used. This is used mostly for debugging purposes.
5957 polling_interval: The interval to poll for changes. Only relevant if
6058 polling is enabled.
61- wait_for_first_timeout: The timeout to use when waiting for the first
62- configuration in
63- [`new_receiver`][frequenz.sdk.config.ConfigManager.new_receiver] if
64- `wait_for_first` is `True`.
6559 """
6660 self .name : Final [str ] = str (id (self )) if name is None else name
6761 """The name of this config manager."""
@@ -80,14 +74,6 @@ def __init__( # pylint: disable=too-many-arguments
8074 )
8175 """The actor that manages the configuration."""
8276
83- self .wait_for_first_timeout : timedelta = wait_for_first_timeout
84- """The timeout to use when waiting for the first configuration.
85-
86- When passing `wait_for_first` as `True` to
87- [`new_receiver`][frequenz.sdk.config.ConfigManager.new_receiver], this timeout
88- will be used to wait for the first configuration to be received.
89- """
90-
9177 # pylint: disable-next=import-outside-toplevel,cyclic-import
9278 from ._logging_actor import LoggingConfigUpdatingActor
9379
@@ -105,7 +91,6 @@ def __repr__(self) -> str:
10591 return (
10692 f"<{ self .__class__ .__name__ } : "
10793 f"name={ self .name !r} , "
108- f"wait_for_first_timeout={ self .wait_for_first_timeout !r} , "
10994 f"config_channel={ self .config_channel !r} , "
11095 f"logging_actor={ self .logging_actor !r} , "
11196 f"config_actor={ self .config_actor !r} >"
@@ -116,19 +101,17 @@ def __str__(self) -> str:
116101 return f"{ type (self ).__name__ } [{ self .name } ]"
117102
118103 @overload
119- async def new_receiver (
104+ def new_receiver (
120105 self ,
121106 * ,
122- wait_for_first : bool = True ,
123107 skip_unchanged : bool = True ,
124108 skip_none : Literal [False ] = False ,
125109 ) -> Receiver [Mapping [str , Any ]]: ...
126110
127111 @overload
128- async def new_receiver ( # pylint: disable=too-many-arguments
112+ def new_receiver ( # pylint: disable=too-many-arguments
129113 self ,
130114 * ,
131- wait_for_first : bool = True ,
132115 skip_unchanged : bool = True ,
133116 skip_none : Literal [False ] = False ,
134117 # We need to specify the key here because we have kwargs, so if it is not
@@ -141,30 +124,27 @@ async def new_receiver( # pylint: disable=too-many-arguments
141124 ) -> Receiver [DataclassT ]: ...
142125
143126 @overload
144- async def new_receiver (
127+ def new_receiver (
145128 self ,
146129 * ,
147- wait_for_first : bool = True ,
148130 skip_unchanged : bool = True ,
149131 skip_none : Literal [False ] = False ,
150132 key : str | Sequence [str ],
151133 ) -> Receiver [Mapping [str , Any ] | None ]: ...
152134
153135 @overload
154- async def new_receiver (
136+ def new_receiver (
155137 self ,
156138 * ,
157- wait_for_first : bool = True ,
158139 skip_unchanged : bool = True ,
159140 skip_none : Literal [True ] = True ,
160141 key : str | Sequence [str ],
161142 ) -> Receiver [Mapping [str , Any ]]: ...
162143
163144 @overload
164- async def new_receiver ( # pylint: disable=too-many-arguments
145+ def new_receiver ( # pylint: disable=too-many-arguments
165146 self ,
166147 * ,
167- wait_for_first : bool = True ,
168148 skip_unchanged : bool = True ,
169149 skip_none : Literal [False ] = False ,
170150 key : str | Sequence [str ],
@@ -174,10 +154,9 @@ async def new_receiver( # pylint: disable=too-many-arguments
174154 ) -> Receiver [DataclassT | None ]: ...
175155
176156 @overload
177- async def new_receiver ( # pylint: disable=too-many-arguments
157+ def new_receiver ( # pylint: disable=too-many-arguments
178158 self ,
179159 * ,
180- wait_for_first : bool = True ,
181160 skip_unchanged : bool = True ,
182161 skip_none : Literal [True ] = True ,
183162 key : str | Sequence [str ],
@@ -188,10 +167,9 @@ async def new_receiver( # pylint: disable=too-many-arguments
188167
189168 # The noqa DOC502 is needed because we raise TimeoutError indirectly.
190169 # pylint: disable-next=too-many-arguments,too-many-locals
191- async def new_receiver ( # noqa: DOC502
170+ def new_receiver ( # noqa: DOC502
192171 self ,
193172 * ,
194- wait_for_first : bool = False ,
195173 skip_unchanged : bool = True ,
196174 skip_none : bool = True ,
197175 # This is tricky, because a str is also a Sequence[str], if we would use only
@@ -264,29 +242,12 @@ async def new_receiver( # noqa: DOC502
264242 Additional arguments can be passed to [`marshmallow.Schema.load`][] using keyword
265243 arguments.
266244
267- ### Waiting for the first configuration
268-
269- If `wait_for_first` is `True`, the receiver will wait for the first
270- configuration to be received before returning the receiver. If the
271- configuration can't be received in time, a timeout error will be raised.
272-
273- If the configuration is received successfully, the first configuration can be
274- simply retrieved by calling [`consume()`][frequenz.channels.Receiver.consume] on
275- the receiver without blocking.
276-
277245 Example:
278246 ```python
279247 # TODO: Add Example
280248 ```
281249
282250 Args:
283- wait_for_first: Whether to wait for the first configuration to be received
284- before returning the receiver. If the configuration can't be received
285- for
286- [`wait_for_first_timeout`][frequenz.sdk.config.ConfigManager.wait_for_first_timeout]
287- time, a timeout error will be raised. If receiving was successful, the
288- first configuration can be simply retrieved by calling
289- [`consume()`][frequenz.channels.Receiver.consume] on the receiver.
290251 skip_unchanged: Whether to skip sending the configuration if it hasn't
291252 changed compared to the last one received.
292253 skip_none: Whether to skip sending the configuration if it is `None`. Only
@@ -303,10 +264,6 @@ async def new_receiver( # noqa: DOC502
303264
304265 Returns:
305266 The receiver for the configuration.
306-
307- Raises:
308- asyncio.TimeoutError: If `wait_for_first` is `True` and the first
309- configuration can't be received in time.
310267 """
311268 # All supporting generic function (using DataclassT) need to be nested
312269 # here. For some reasons mypy has trouble if these functions are
@@ -397,10 +354,6 @@ def _is_mapping(
397354 if skip_unchanged :
398355 receiver = receiver .filter (WithPrevious (_NotEqualWithLogging (key )))
399356
400- if wait_for_first :
401- async with asyncio .timeout (self .wait_for_first_timeout .total_seconds ()):
402- await receiver .ready ()
403-
404357 match (key , schema ):
405358 case (None , None ):
406359 assert_type (receiver , Receiver [Mapping [str , Any ]])
0 commit comments