Send signal from sender to all connected receivers. If any receiver raises an error, the error propagates back through send, terminating the dispatch loop. So it's possible that all receivers won't be called if an error is raised. If any receivers are async
(self, sender, **named)
| 217 | return bool(sync_receivers) or bool(async_receivers) |
| 218 | |
| 219 | def send(self, sender, **named): |
| 220 | """ |
| 221 | Send signal from sender to all connected receivers. |
| 222 | |
| 223 | If any receiver raises an error, the error propagates back through |
| 224 | send, terminating the dispatch loop. So it's possible that all |
| 225 | receivers won't be called if an error is raised. |
| 226 | |
| 227 | If any receivers are asynchronous, they are called after all the |
| 228 | synchronous receivers via a single call to async_to_sync(). They are |
| 229 | also executed concurrently with asyncio.TaskGroup(). |
| 230 | |
| 231 | Arguments: |
| 232 | |
| 233 | sender |
| 234 | The sender of the signal. Either a specific object or None. |
| 235 | |
| 236 | named |
| 237 | Named arguments which will be passed to receivers. |
| 238 | |
| 239 | Return a list of tuple pairs [(receiver, response), ... ]. |
| 240 | """ |
| 241 | if ( |
| 242 | not self.receivers |
| 243 | or self.sender_receivers_cache.get(sender) is NO_RECEIVERS |
| 244 | ): |
| 245 | return [] |
| 246 | responses = [] |
| 247 | sync_receivers, async_receivers = self._live_receivers(sender) |
| 248 | for receiver in sync_receivers: |
| 249 | response = receiver(signal=self, sender=sender, **named) |
| 250 | responses.append((receiver, response)) |
| 251 | if async_receivers: |
| 252 | |
| 253 | async def asend(): |
| 254 | async_responses = await _run_parallel( |
| 255 | *( |
| 256 | receiver(signal=self, sender=sender, **named) |
| 257 | for receiver in async_receivers |
| 258 | ) |
| 259 | ) |
| 260 | return zip(async_receivers, async_responses) |
| 261 | |
| 262 | responses.extend(async_to_sync(asend)()) |
| 263 | return responses |
| 264 | |
| 265 | async def asend(self, sender, **named): |
| 266 | """ |